22
33namespace App \Extensions \PaymentGateways \Mollie ;
44
5- use App \Classes \AbstractExtension ;
5+ use App \Classes \PaymentExtension ;
66use App \Enums \PaymentStatus ;
77use App \Events \PaymentEvent ;
88use App \Events \UserUpdateCreditsEvent ;
99use App \Models \Payment ;
1010use App \Models \ShopProduct ;
1111use App \Models \User ;
1212use App \Notifications \ConfirmPaymentNotification ;
13- use App \Traits \Coupon as CouponTrait ;
1413use Exception ;
1514use Illuminate \Http \JsonResponse ;
1615use Illuminate \Http \RedirectResponse ;
2221/**
2322 * Summary of PayPalExtension
2423 */
25- class MollieExtension extends AbstractExtension
24+ class MollieExtension extends PaymentExtension
2625{
27- use CouponTrait;
28-
2926 public static function getConfig (): array
3027 {
3128 return [
@@ -36,8 +33,16 @@ public static function getConfig(): array
3633 ];
3734 }
3835
39- public static function getRedirectUrl (Payment $ payment , ShopProduct $ shopProduct , string $ totalPriceString ): string
36+ public static function getRedirectUrl (Payment $ payment , ShopProduct $ shopProduct , int $ totalPrice ): string
4037 {
38+ /**
39+ * Mollie requires the price to be a string with two decimal places.
40+ * The price is in cents, so we need to divide by 10 to get the value in 100 factors.
41+ * The price is also in the format of 0.00, so we need to format it to two decimal places.
42+ */
43+ $ priceCents = $ totalPrice / 10 ;
44+ $ totalPrice = number_format ($ priceCents / 100 , 2 , '. ' , '' );
45+
4146 $ url = 'https://api.mollie.com/v2/payments ' ;
4247 $ settings = new MollieSettings ();
4348 try {
@@ -47,7 +52,7 @@ public static function getRedirectUrl(Payment $payment, ShopProduct $shopProduct
4752 ])->post ($ url , [
4853 'amount ' => [
4954 'currency ' => $ shopProduct ->currency_code ,
50- 'value ' => $ totalPriceString ,
55+ 'value ' => $ totalPrice ,
5156 ],
5257 'description ' => "Order # {$ payment ->id } - " . $ shopProduct ->name ,
5358 'redirectUrl ' => route ('payment.MollieSuccess ' , ['payment_id ' => $ payment ->id ]),
0 commit comments