diff --git a/Model/Paymentmethod/Paylink.php b/Model/Paymentmethod/Paylink.php
index caf06f8c..ca5a020a 100644
--- a/Model/Paymentmethod/Paylink.php
+++ b/Model/Paymentmethod/Paylink.php
@@ -4,6 +4,7 @@
use Magento\Sales\Model\Order;
use Magento\Framework\DataObject;
+use Paynl\Payment\Helper\PayHelper;
class Paylink extends PaymentMethod
{
@@ -54,93 +55,112 @@ public function initialize($paymentAction, $stateObject)
$send_paylink_email = $this->_scopeConfig->getValue('payment/paynl_payment_paylink/send_paylink_email', 'store', $storeId);
if ($send_paylink_email == 0) {
- $paylinktext = __('PAY.: Here is your ');
- $postText = __('Open or copy the link to share.');
- $order->addStatusHistoryComment($paylinktext . 'PAY. Link. ' . $postText, $status);
+ $this->addPaylinkComment($order, $url, $status);
} else {
- $paylinktext = __('A PAY. Paylink has been send to');
- $order->addStatusHistoryComment($paylinktext . ' ' . $order->getCustomerEmail() . '.', $status);
-
- $supportEmail = $this->_scopeConfig->getValue('trans_email/ident_support/email', 'store', $storeId);
- $senderName = $this->_scopeConfig->getValue('trans_email/ident_sales/name', 'store', $storeId);
- $senderEmail = $this->_scopeConfig->getValue('trans_email/ident_sales/email', 'store', $storeId);
-
- $sender = [
- 'name' => $senderName,
- 'email' => $senderEmail,
- ];
-
- $customerEmail = [$order->getCustomerEmail()];
-
- $paymentHelper = $objectManager->create(\Magento\Payment\Helper\Data::class);
-
- $orderHTML = $paymentHelper->getInfoBlockHtml(
- $order->getPayment(),
- $storeId
- );
-
- $addressRenderer = $objectManager->create(\Magento\Sales\Model\Order\Address\Renderer::class);
-
- $show_order_in_mail = $this->_scopeConfig->getValue('payment/paynl_payment_paylink/show_order_in_mail', 'store', $storeId);
- if ($show_order_in_mail) {
- $show_order_in_mail = 1;
- } else {
- $show_order_in_mail = 0;
+ try {
+ $customerEmail = [$order->getCustomerEmail()];
+
+ if (empty($customerEmail)) {
+ # Can't send email without customer email so add paylink as a comment instead.
+ $order->addStatusHistoryComment(__('PAY.: Customer E-mail is empty cannot send E-mail.'), $status)->save();
+ $this->addPaylinkComment($order, $url, $status);
+ return false;
+ }
+
+ $supportEmail = $this->_scopeConfig->getValue('trans_email/ident_support/email', 'store', $storeId);
+ $senderName = $this->_scopeConfig->getValue('trans_email/ident_sales/name', 'store', $storeId);
+ $senderEmail = $this->_scopeConfig->getValue('trans_email/ident_sales/email', 'store', $storeId);
+
+ $sender = [
+ 'name' => $senderName,
+ 'email' => $senderEmail,
+ ];
+
+ $paymentHelper = $objectManager->create(\Magento\Payment\Helper\Data::class);
+
+ $orderHTML = $paymentHelper->getInfoBlockHtml(
+ $order->getPayment(),
+ $storeId
+ );
+
+ $addressRenderer = $objectManager->create(\Magento\Sales\Model\Order\Address\Renderer::class);
+
+ $show_order_in_mail = $this->_scopeConfig->getValue('payment/paynl_payment_paylink/show_order_in_mail', 'store', $storeId);
+ if ($show_order_in_mail) {
+ $show_order_in_mail = 1;
+ } else {
+ $show_order_in_mail = 0;
+ }
+
+ $subject = $this->_scopeConfig->getValue('payment/paynl_payment_paylink/paylink_subject', 'store', $storeId);
+ $subject = str_replace('((paylink))', '' . __('PAY. paylink') . '', $subject);
+ $subject = str_replace('((customer_name))', $order->getCustomerName(), $subject);
+ $subject = str_replace('((store_name))', $order->getStore()->getName(), $subject);
+ $subject = str_replace('((support_email))', '' . $supportEmail . '', $subject);
+ $subject = str_replace('((order_id))', $order->getIncrementId(), $subject);
+
+ $body = $this->_scopeConfig->getValue('payment/paynl_payment_paylink/paylink_body', 'store', $storeId);
+ $body = nl2br($body);
+ $body = str_replace('((paylink))', '' . __('PAY. paylink') . '', $body);
+ $body = str_replace('((customer_name))', $order->getCustomerName(), $body);
+ $body = str_replace('((store_name))', $order->getStore()->getName(), $body);
+ $body = str_replace('((support_email))', '' . $supportEmail . '', $body);
+ $body = str_replace('((order_id))', $order->getIncrementId(), $body);
+
+ $templateVars = [
+ 'subject' => $subject,
+ 'body' => $body,
+ 'order' => $order,
+ 'store' => $store,
+ 'customer_name' => $order->getCustomerName(),
+ 'paylink' => $url,
+ 'support_email' => $supportEmail,
+ 'current_language' => $lang,
+ 'order_id' => $order->getIncrementId(),
+ 'billing' => $order->getBillingAddress(),
+ 'payment_html' => $orderHTML,
+ 'formattedShippingAddress' => $order->getIsVirtual() ? null : $addressRenderer->format($order->getShippingAddress(), 'html'),
+ 'formattedBillingAddress' => $addressRenderer->format($order->getBillingAddress(), 'html'),
+ 'created_at_formatted' => $order->getCreatedAtFormatted(1),
+ 'customer_name' => $order->getCustomerName(),
+ 'is_not_virtual' => $order->getIsNotVirtual(),
+ 'email_customer_note' => $order->getEmailCustomerNote(),
+ 'frontend_status_label' => $order->getFrontendStatusLabel(),
+ 'show_order_in_mail' => $show_order_in_mail,
+ ];
+
+ $transportBuilder = $objectManager->create(\Magento\Framework\Mail\Template\TransportBuilder::class);
+
+ payHelper::logDebug('Sending Paylink E-mail with the following user data: ', array("sender" => $sender, "customer_email" => $customerEmail, "support_email" => $supportEmail));
+ $transport = $transportBuilder->setTemplateIdentifier('paylink_email_template')
+ ->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId])
+ ->setTemplateVars($templateVars)
+ ->setFrom($sender)
+ ->addTo($customerEmail)
+ ->setReplyTo($supportEmail)
+ ->getTransport();
+ $transport->sendMessage();
+
+ $paylinktext = __('A PAY. Paylink has been send to');
+ $order->addStatusHistoryComment($paylinktext . ' ' . $order->getCustomerEmail() . '.', $status)->save();
+ } catch (\Exception $e) {
+ payHelper::logDebug('Paylink exception: ' . $e->getMessage());
+ $order->addStatusHistoryComment(__('PAY.: Unable to send E-mail'), $status)->save();
+ $this->addPaylinkComment($order, $url, $status);
}
-
- $subject = $this->_scopeConfig->getValue('payment/paynl_payment_paylink/paylink_subject', 'store', $storeId);
- $subject = str_replace('((paylink))', '' . __('PAY. paylink') . '', $subject);
- $subject = str_replace('((customer_name))', $order->getCustomerName(), $subject);
- $subject = str_replace('((store_name))', $order->getStore()->getName(), $subject);
- $subject = str_replace('((support_email))', '' . $supportEmail . '', $subject);
- $subject = str_replace('((order_id))', $order->getIncrementId(), $subject);
-
- $body = $this->_scopeConfig->getValue('payment/paynl_payment_paylink/paylink_body', 'store', $storeId);
- $body = nl2br($body);
- $body = str_replace('((paylink))', '' . __('PAY. paylink') . '', $body);
- $body = str_replace('((customer_name))', $order->getCustomerName(), $body);
- $body = str_replace('((store_name))', $order->getStore()->getName(), $body);
- $body = str_replace('((support_email))', '' . $supportEmail . '', $body);
- $body = str_replace('((order_id))', $order->getIncrementId(), $body);
-
- $templateVars = [
- 'subject' => $subject,
- 'body' => $body,
- 'order' => $order,
- 'store' => $store,
- 'customer_name' => $order->getCustomerName(),
- 'paylink' => $url,
- 'support_email' => $supportEmail,
- 'current_language' => $lang,
- 'order_id' => $order->getIncrementId(),
- 'billing' => $order->getBillingAddress(),
- 'payment_html' => $orderHTML,
- 'formattedShippingAddress' => $order->getIsVirtual() ? null : $addressRenderer->format($order->getShippingAddress(), 'html'),
- 'formattedBillingAddress' => $addressRenderer->format($order->getBillingAddress(), 'html'),
- 'created_at_formatted' => $order->getCreatedAtFormatted(1),
- 'customer_name' => $order->getCustomerName(),
- 'is_not_virtual' => $order->getIsNotVirtual(),
- 'email_customer_note' => $order->getEmailCustomerNote(),
- 'frontend_status_label' => $order->getFrontendStatusLabel(),
- 'show_order_in_mail' => $show_order_in_mail,
- ];
-
- $transportBuilder = $objectManager->create(\Magento\Framework\Mail\Template\TransportBuilder::class);
-
- $transport = $transportBuilder->setTemplateIdentifier('paylink_email_template')
- ->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId])
- ->setTemplateVars($templateVars)
- ->setFrom($sender)
- ->addTo($customerEmail)
- ->setReplyTo($supportEmail)
- ->getTransport();
- $transport->sendMessage();
}
parent::initialize($paymentAction, $stateObject);
}
}
+ public function addPaylinkComment($order, $url, $status)
+ {
+ $paylinktext = __('PAY.: Here is your ');
+ $postText = __('Open or copy the link to share.');
+ $order->addStatusHistoryComment($paylinktext . 'PAY. Link. ' . $postText, $status)->save();
+ }
+
public function assignData(\Magento\Framework\DataObject $data)
{
$this->getInfoInstance()->setAdditionalInformation('valid_days', $data->getData('additional_data')['valid_days']);
diff --git a/i18n/nl_NL.csv b/i18n/nl_NL.csv
index fa4d9a58..e54bd66a 100644
--- a/i18n/nl_NL.csv
+++ b/i18n/nl_NL.csv
@@ -157,4 +157,6 @@
"Set PAY. loglevel","Geef aan tot welk niveau logregels moeten worden opgeslagen"
"Select whether you want PAY. style applied to your checkout.","Geef aan of u PAY. styling wilt toepassen in uw checkout(Deze is vereist voor de optie `Icoon Grootte`)."
"Select whether you want to use classic icons, or the newest up-to-date icons.","Geef aan of u de oude stijl betaaliconen wilt gebruiken, of liever de meest up-to-date set afbeeldingen."
-"Payment has been canceled","Betaling is geannuleerd"
\ No newline at end of file
+"Payment has been canceled","Betaling is geannuleerd"
+"PAY.: Unable to send E-mail", "PAY.: Kan geen e-mail verzenden"
+"PAY.: Customer E-mail is empty cannot send E-mail.", "PAY.: E-mail klant is leeg kan geen e-mail verzenden."
\ No newline at end of file