diff --git a/mails/en/mollie_subscription_cancel.html b/mails/en/mollie_subscription_cancel.html index 73517e93e..0922507b0 100644 --- a/mails/en/mollie_subscription_cancel.html +++ b/mails/en/mollie_subscription_cancel.html @@ -576,7 +576,7 @@ > -ReferenceProductUnit priceQuantityTotal price +ReferenceProductUnit price(tax excl.)QuantityTotal price subscription_referenceproduct_nameunit_pricequantitytotal_price @@ -677,4 +677,4 @@

- \ No newline at end of file + diff --git a/mails/en/mollie_subscription_cancel.txt b/mails/en/mollie_subscription_cancel.txt index b6af45818..f7a2f4597 100644 --- a/mails/en/mollie_subscription_cancel.txt +++ b/mails/en/mollie_subscription_cancel.txt @@ -1,9 +1,9 @@ -Hi firstName lastName, - - -We are emailing you because the following item was set to renew and that the payment method on file failed. Please log in into your account and update the payment method. - -We’ll keep trying to process your payment however if it continues to fail your subscription will get cancelled. -t -Reference Product Unit price Quantity Total price -subscription_reference product_name unit_price quantity total_price +Hi firstName lastName, + + +We are emailing you because the following item was set to renew and that the payment method on file failed. Please log in into your account and update the payment method. + +We’ll keep trying to process your payment however if it continues to fail your subscription will get cancelled. + +Reference Product Unit price(tax excl.) Quantity Total price +subscription_reference product_name unit_price quantity total_price diff --git a/mails/en/mollie_subscription_carrier_update.html b/mails/en/mollie_subscription_carrier_update.html new file mode 100644 index 000000000..3e2197e9d --- /dev/null +++ b/mails/en/mollie_subscription_carrier_update.html @@ -0,0 +1,680 @@ + + + + + Payment + + + + + + + + + + + + + + + + + + + + + + + + +
+
 
+ +
+ + + + + + +
+
+ + + + + + +
+
+ + + + + + +
+ + + + + + +
+
+
+
+
+ +
+ + + + + + +
+
+ + + + + + +
+ + + + + + +
+
Hi firstName lastName,
+
+
+
+
+
+ +
+ + + + + + +
+
+ + + + + + +
+

+
+
+
+
+ +
+ + + + + + +
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + +
+
We are emailing you because the following subscription carrier was updated.
+
+
+
+
Log in to you account to review updated subscription information.
+
+
+
+
+
+ +
t + + + + + + + + +
ReferenceProductUnit price(tax excl.)QuantityTotal price
subscription_referenceproduct_nameunit_pricequantitytotal_price
+
+
+
+
+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +
+ +

+ +

+ +

+ +

+

+ + + diff --git a/mails/en/mollie_subscription_carrier_update.txt b/mails/en/mollie_subscription_carrier_update.txt new file mode 100644 index 000000000..93eb81f03 --- /dev/null +++ b/mails/en/mollie_subscription_carrier_update.txt @@ -0,0 +1,8 @@ +Hi firstName lastName, + +We are emailing you because the following subscription carrier was updated. + +Log in to you account to review updated subscription information. + +Reference Product Unit price(tax excl.) Quantity Total price +subscription_reference product_name unit_price quantity total_price diff --git a/mails/en/mollie_subscription_payment_failed.html b/mails/en/mollie_subscription_payment_failed.html index b136eff26..48dca56d7 100644 --- a/mails/en/mollie_subscription_payment_failed.html +++ b/mails/en/mollie_subscription_payment_failed.html @@ -566,7 +566,7 @@ > -ReferenceProductUnit priceQuantityTotal price +ReferenceProductUnit price(tax excl.)QuantityTotal price subscription_referenceproduct_nameunit_pricequantitytotal_price diff --git a/mails/en/mollie_subscription_payment_failed.txt b/mails/en/mollie_subscription_payment_failed.txt index b1e76f549..6bb73fa29 100644 --- a/mails/en/mollie_subscription_payment_failed.txt +++ b/mails/en/mollie_subscription_payment_failed.txt @@ -1,7 +1,7 @@ -Hi firstName lastName, - - -We are emailing you because we have retried to process the payment and failed. Your subscription has been cancelled. - -Reference Product Unit price Quantity Total price -subscription_reference product_name unit_price quantity total_price +Hi firstName lastName, + + +We are emailing you because we have retried to process the payment and failed. Your subscription has been cancelled. + +Reference Product Unit price(tax excl.) Quantity Total price +subscription_reference product_name unit_price quantity total_price diff --git a/src/Service/MailService.php b/src/Service/MailService.php index 3d55cf5ce..843bf685f 100644 --- a/src/Service/MailService.php +++ b/src/Service/MailService.php @@ -18,20 +18,14 @@ use CartRule; use Configuration; use Context; -use Currency; use Customer; use Hook; use Language; use Mail; use Mollie; use Mollie\Adapter\ProductAttributeAdapter; -use Mollie\Adapter\ToolsAdapter; use Mollie\Exception\MollieException; -use Mollie\Subscription\Repository\RecurringOrderRepositoryInterface; -use Mollie\Subscription\Repository\RecurringOrdersProductRepositoryInterface; -use Mollie\Utility\NumberUtility; -use MolRecurringOrder; -use MolRecurringOrdersProduct; +use Mollie\Subscription\Provider\GeneralSubscriptionMailDataProvider; use Order; use OrderState; use PDF; @@ -47,37 +41,24 @@ class MailService { const FILE_NAME = 'MailService'; - /** - * @var Mollie - */ + /** @var Mollie */ private $module; - - /** - * @var Context - */ + /** @var Context */ private $context; /** @var ProductAttributeAdapter */ private $productAttributeAdapter; - /** @var RecurringOrderRepositoryInterface */ - private $recurringOrderRepository; - /** @var RecurringOrdersProductRepositoryInterface */ - private $recurringOrdersProductRepository; - /** @var ToolsAdapter */ - private $toolsAdapter; + /** @var GeneralSubscriptionMailDataProvider */ + private $generalSubscriptionMailDataProvider; public function __construct( Mollie $module, ProductAttributeAdapter $productAttributeAdapter, - RecurringOrderRepositoryInterface $recurringOrderRepository, - RecurringOrdersProductRepositoryInterface $recurringOrdersProductRepository, - ToolsAdapter $toolsAdapter + GeneralSubscriptionMailDataProvider $generalSubscriptionMailDataProvider ) { $this->module = $module; $this->context = Context::getContext(); $this->productAttributeAdapter = $productAttributeAdapter; - $this->recurringOrderRepository = $recurringOrderRepository; - $this->recurringOrdersProductRepository = $recurringOrdersProductRepository; - $this->toolsAdapter = $toolsAdapter; + $this->generalSubscriptionMailDataProvider = $generalSubscriptionMailDataProvider; } public function sendSecondChanceMail(Customer $customer, $checkoutUrl, $methodName, $shopId) @@ -136,35 +117,22 @@ public function sendOrderConfMail(Order $order, $orderStateId) */ public function sendSubscriptionCancelWarningEmail(int $recurringOrderId): void { - /** @var \MolRecurringOrder $recurringOrder */ - $recurringOrder = $this->recurringOrderRepository->findOrFail([ - 'id_mol_recurring_order' => $recurringOrderId, - ]); - - /** @var \MolRecurringOrdersProduct $recurringOrderProduct */ - $recurringOrderProduct = $this->recurringOrdersProductRepository->findOrFail([ - 'id_mol_recurring_orders_product' => $recurringOrder->id_mol_recurring_orders_product, - ]); - - $customer = new Customer($recurringOrder->id_customer); - $product = new Product($recurringOrderProduct->id_product, false, $customer->id_lang); - - $data = $this->getSubscriptionCancellationWarningMailData($recurringOrder, $recurringOrderProduct, $customer); + $data = $this->generalSubscriptionMailDataProvider->run($recurringOrderId); Mail::Send( - (int) $customer->id_lang, + $data->getLangId(), 'mollie_subscription_cancel', - sprintf(Mail::l('Your payment for the subscription of %s failed', (int) $customer->id_lang), $product->name), - $data, - $customer->email, - implode(' ', [$customer->firstname, $customer->lastname]), + sprintf(Mail::l('Your payment for the subscription of %s failed', $data->getLangId()), $data->getProductName()), + $data->toArray(), + $data->getCustomerEmail(), + implode(' ', [$data->getFirstName(), $data->getLastName()]), null, null, null, null, $this->module->getLocalPath() . 'mails/', false, - (int) $customer->id_shop + $data->getShopId() ); } @@ -173,64 +141,49 @@ public function sendSubscriptionCancelWarningEmail(int $recurringOrderId): void */ public function sendSubscriptionPaymentFailWarningMail(int $recurringOrderId): void { - /** @var \MolRecurringOrder $recurringOrder */ - $recurringOrder = $this->recurringOrderRepository->findOrFail([ - 'id_mol_recurring_order' => $recurringOrderId, - ]); - - /** @var \MolRecurringOrdersProduct $recurringOrderProduct */ - $recurringOrderProduct = $this->recurringOrdersProductRepository->findOrFail([ - 'id_mol_recurring_orders_product' => $recurringOrder->id_mol_recurring_orders_product, - ]); - - $customer = new Customer($recurringOrder->id_customer); - $product = new Product($recurringOrderProduct->id_product, false, $customer->id_lang); - - $data = $this->getSubscriptionCancellationWarningMailData($recurringOrder, $recurringOrderProduct, $customer); + $data = $this->generalSubscriptionMailDataProvider->run($recurringOrderId); Mail::Send( - (int) $customer->id_lang, + $data->getLangId(), 'mollie_subscription_payment_failed', - sprintf(Mail::l('Your subscription for %s cancelled', (int) $customer->id_lang), $product->name), - $data, - $customer->email, - implode(' ', [$customer->firstname, $customer->lastname]), + sprintf(Mail::l('Your subscription for %s cancelled', $data->getLangId()), $data->getProductName()), + $data->toArray(), + $data->getCustomerEmail(), + implode(' ', [$data->getFirstName(), $data->getLastName()]), null, null, null, null, $this->module->getLocalPath() . 'mails/', false, - (int) $customer->id_shop + $data->getShopId() ); } - private function getSubscriptionCancellationWarningMailData( - MolRecurringOrder $recurringOrder, - MolRecurringOrdersProduct $recurringOrderProduct, - Customer $customer - ): array { - $product = new Product($recurringOrderProduct->id_product, false, $customer->id_lang); - - $totalPrice = NumberUtility::toPrecision( - (float) $recurringOrder->total_tax_incl, - NumberUtility::DECIMAL_PRECISION - ); - - $unitPrice = NumberUtility::toPrecision( - (float) $recurringOrderProduct->unit_price, - NumberUtility::DECIMAL_PRECISION + /** + * @throws MollieException + */ + public function sendSubscriptionCarrierUpdateMail(int $recurringOrderId): bool + { + $data = $this->generalSubscriptionMailDataProvider->run($recurringOrderId); + + $result = Mail::Send( + $data->getLangId(), + 'mollie_subscription_carrier_update', + sprintf(Mail::l('Your subscription for %s carrier was updated', $data->getLangId()), $data->getProductName()), + $data->toArray(), + $data->getCustomerEmail(), + implode(' ', [$data->getFirstName(), $data->getLastName()]), + null, + null, + null, + null, + $this->module->getLocalPath() . 'mails/', + false, + $data->getShopId() ); - return [ - 'subscription_reference' => $recurringOrder->mollie_subscription_id, - 'product_name' => $product->name, - 'unit_price' => $this->toolsAdapter->displayPrice($unitPrice, new Currency($recurringOrder->id_currency)), - 'quantity' => $recurringOrderProduct->quantity, - 'total_price' => $this->toolsAdapter->displayPrice($totalPrice, new Currency($recurringOrder->id_currency)), - 'firstName' => $customer->firstname, - 'lastName' => $customer->lastname, - ]; + return !(is_bool($result) && !$result); } /** diff --git a/subscription/Provider/GeneralSubscriptionMailDataProvider.php b/subscription/Provider/GeneralSubscriptionMailDataProvider.php index c587e408f..35fb6b43d 100644 --- a/subscription/Provider/GeneralSubscriptionMailDataProvider.php +++ b/subscription/Provider/GeneralSubscriptionMailDataProvider.php @@ -89,6 +89,7 @@ public function run(int $recurringOrderId): GeneralSubscriptionMailData 'id_currency' => $recurringOrder->id_currency, ]); + // TODO would be great to get unitPriceTaxIncl $unitPriceTaxExcl = (float) $this->context->formatPrice( NumberUtility::toPrecision( (float) $recurringOrderProduct->unit_price,