@@ -19,7 +19,7 @@ abstract class WC_Abstract_Payline extends WC_Payment_Gateway {
1919
2020 protected $ paymentMode = '' ;
2121
22- protected $ extensionVersion = '1.5.1 ' ;
22+ protected $ extensionVersion = '1.5.2 ' ;
2323
2424 /** @var int Payline internal API version */
2525 protected $ APIVersion = 26 ;
@@ -675,9 +675,11 @@ function getRawRedirectUrl($order_id) {
675675 $ order = wc_get_order ($ order_id );
676676
677677 $ this ->SDK = $ this ->getSDK ();
678+ $ redirectURL = $ this ->getCachedDWPDataForOrder ($ order , 'redirectURL ' , true );
678679
679680
680- $ redirectURL = $ this ->getCachedDWPDataForOrder ($ order , 'redirectURL ' , true );
681+ $ errorCode = $ this ->SDK ::ERR_CODE ;
682+ $ errorMsg = $ this ->SDK ::ERR_SHORT_MESSAGE ;
681683
682684 if ( !$ redirectURL ) {
683685 $ requestParams = $ this ->getWebPaymentRequest ($ order );
@@ -688,10 +690,13 @@ function getRawRedirectUrl($order_id) {
688690 if ( $ result ['result ' ]['code ' ] === '00000 ' ) {
689691 $ this ->updateTokenForOrder ($ order , $ result );
690692 return $ result ['redirectURL ' ];
693+ } else {
694+ $ errorCode = $ result ['result ' ]['code ' ];
695+ $ errorMsg = $ result ['result ' ]['longMessage ' ];
691696 }
692697 }
693698
694- $ message = sprintf ( __ ( 'You can \'t be redirected to payment page (error code ' . $ result [ ' result ' ][ ' code ' ] . ' : ' . $ result [ ' result ' ][ ' longMessage ' ] . ' ). Please contact us. ' , 'payline ' ), ' Payline ' );
699+ $ message = sprintf ( __ ( 'You can \'t be redirected to payment page (error code %s : %s ). Please contact us. ' , 'payline ' ), $ errorCode , $ errorMsg );
695700 return $ this ->get_error_payment_url ($ order , $ message );
696701 }
697702
@@ -820,10 +825,12 @@ protected function getWebPaymentRequest(WC_Order $order)
820825
821826 $ doWebPaymentRequest ['order ' ]['ref ' ] = $ this ->cleanSubstr ($ order ->get_id (), 0 , 50 );
822827 $ doWebPaymentRequest ['order ' ]['country ' ] = $ order ->get_billing_country ();
823- $ doWebPaymentRequest ['order ' ]['taxes ' ] = round ($ order ->get_total_tax ());
828+ $ doWebPaymentRequest ['order ' ]['taxes ' ] = round (( $ order ->get_total_tax () - $ order -> get_shipping_tax ()) * 100 );
824829 $ doWebPaymentRequest ['order ' ]['amount ' ] = $ doWebPaymentRequest ['payment ' ]['amount ' ];
825830 $ doWebPaymentRequest ['order ' ]['date ' ] = date (self ::PAYLINE_DATE_FORMAT );
826831 $ doWebPaymentRequest ['order ' ]['currency ' ] = $ doWebPaymentRequest ['payment ' ]['currency ' ];
832+ $ doWebPaymentRequest ['order ' ]['deliveryCharge ' ] = round (($ order ->get_shipping_total () + $ order ->get_shipping_tax ()) * 100 );
833+ //$doWebPaymentRequest['order']['discountAmount'] = round(($order->get_discount_total() + $order->get_discount_tax()) * 100);
827834
828835 // BUYER
829836 // TODO: Default value
@@ -860,26 +867,49 @@ protected function getWebPaymentRequest(WC_Order $order)
860867 $ doWebPaymentRequest ['shippingAddress ' ]['name ' ] .= ' ( ' . $ order ->get_shipping_company () . ') ' ;
861868 }
862869 $ doWebPaymentRequest ['shippingAddress ' ]['name ' ] = $ this ->cleanSubstr ($ doWebPaymentRequest ['shippingAddress ' ]['name ' ], 0 , 100 );
863- $ doWebPaymentRequest ['shippingAddress ' ]['firstName ' ] = $ this ->cleanSubstr ($ order ->get_shipping_first_name (), 0 , 100 );
864- $ doWebPaymentRequest ['shippingAddress ' ]['lastName ' ] = $ this ->cleanSubstr ($ order ->get_shipping_last_name (), 0 , 100 );
865- $ doWebPaymentRequest ['shippingAddress ' ]['street1 ' ] = $ this ->cleanSubstr ($ order ->get_shipping_address_1 (), 0 , 100 );
866- $ doWebPaymentRequest ['shippingAddress ' ]['street2 ' ] = $ this ->cleanSubstr ($ order ->get_shipping_address_2 (), 0 , 100 );
867- $ doWebPaymentRequest ['shippingAddress ' ]['cityName ' ] = $ this ->cleanSubstr ($ order ->get_shipping_city (), 0 , 40 );
868- $ doWebPaymentRequest ['shippingAddress ' ]['zipCode ' ] = $ this ->cleanSubstr ($ order ->get_shipping_postcode (), 0 , 20 );
869- $ doWebPaymentRequest ['shippingAddress ' ]['country ' ] = $ order ->get_shipping_country ();
870+ $ doWebPaymentRequest ['shippingAddress ' ]['firstName ' ] = $ this ->cleanSubstr ($ order ->get_shipping_first_name ()?: $ order -> get_billing_first_name () , 0 , 100 );
871+ $ doWebPaymentRequest ['shippingAddress ' ]['lastName ' ] = $ this ->cleanSubstr ($ order ->get_shipping_last_name ()?: $ order -> get_billing_last_name () , 0 , 100 );
872+ $ doWebPaymentRequest ['shippingAddress ' ]['street1 ' ] = $ this ->cleanSubstr ($ order ->get_shipping_address_1 ()?: $ order -> get_billing_address_1 () , 0 , 100 );
873+ $ doWebPaymentRequest ['shippingAddress ' ]['street2 ' ] = $ this ->cleanSubstr ($ order ->get_shipping_address_2 ()?: $ order -> get_billing_address_2 () , 0 , 100 );
874+ $ doWebPaymentRequest ['shippingAddress ' ]['cityName ' ] = $ this ->cleanSubstr ($ order ->get_shipping_city ()?: $ order -> get_billing_city () , 0 , 40 );
875+ $ doWebPaymentRequest ['shippingAddress ' ]['zipCode ' ] = $ this ->cleanSubstr ($ order ->get_shipping_postcode ()?: $ order -> get_billing_postcode () , 0 , 20 );
876+ $ doWebPaymentRequest ['shippingAddress ' ]['country ' ] = $ order ->get_shipping_country ()?: $ order -> get_billing_country () ;
870877 $ doWebPaymentRequest ['shippingAddress ' ]['phone ' ] = '' ;
871878
879+ $ totalOrderLines = 0 ;
872880 // ORDER DETAILS
873881 $ items = $ order ->get_items ();
874- foreach ($ items as $ item ) {
875- $ this ->SDK ->addOrderDetail (array (
882+ /** @var WC_Order_Item_Product $item */
883+ foreach ($ items as $ item ) {
884+ $ orderLine = array (
876885 'ref ' => $ this ->cleanSubstr ($ item ['name ' ], 0 , 50 ),
877- 'price ' => round ($ item ['line_total ' ] * 100 ),
878- 'quantity ' => $ item ['qty ' ],
879- 'comment ' => ''
880- ));
886+ 'price ' => round (($ item ->get_subtotal () + $ item ->get_subtotal_tax ())/$ item ['qty ' ],2 ) * 100 ,
887+ 'quantity ' => (int )$ item ['qty ' ],
888+ 'comment ' => (string )$ item ['name ' ],
889+ 'taxRate ' => round (($ item ['total_tax ' ] / $ item ['total ' ]) * 100 * 100 )
890+ );
891+ $ this ->SDK ->addOrderDetail ($ orderLine );
892+
893+ $ totalOrderLines +=$ orderLine ['price ' ] * $ orderLine ['quantity ' ];
881894 }
882895
896+ //Allow Klarna with cart discount
897+ //$adjustment = $doWebPaymentRequest['order']['amount'] - $totalOrderLines - $doWebPaymentRequest['order']['deliveryCharge'] - $doWebPaymentRequest['order']['discountAmount'];
898+ $ adjustment = $ doWebPaymentRequest ['order ' ]['amount ' ] - $ totalOrderLines - $ doWebPaymentRequest ['order ' ]['deliveryCharge ' ];
899+ if ($ adjustment ) {
900+ $ prixHT = ($ order ->get_total () - $ order ->get_total_tax () - $ order ->get_shipping_total ());
901+ $ taxRate = round (($ order ->get_cart_tax () / $ prixHT ) * 100 * 100 );
902+
903+ $ this ->SDK ->addOrderDetail (array (
904+ 'ref ' => 'CART_DISCOUNT ' ,
905+ 'price ' => $ adjustment ,
906+ 'quantity ' => 1 ,
907+ 'comment ' => 'Cart amount adjustment ' ,
908+ 'category ' => 'main ' ,
909+ 'taxRate ' => $ taxRate
910+ ));
911+ }
912+
883913 // TRANSACTION OPTIONS
884914 $ doWebPaymentRequest ['notificationURL ' ] = $ this ->get_request_url ('notification ' );
885915 $ doWebPaymentRequest ['returnURL ' ] = $ this ->get_request_url ('return ' );
@@ -1008,7 +1038,7 @@ function generate_payline_form($order_id) {
10081038
10091039 exit ;
10101040 } else {
1011- $ message = sprintf ( __ ( 'You can \'t be redirected to payment page (error code ' . $ result ['result ' ]['code ' ] . ' : ' . $ result ['result ' ]['longMessage ' ] . ' ). Please contact us. ' , ' payline ' ), ' Payline ' );
1041+ $ message = sprintf ( __ ( 'You can \'t be redirected to payment page (error code %s : %s). Please contact us. ' , ' payline ' ), $ result ['result ' ]['code ' ], $ result ['result ' ]['longMessage ' ]);
10121042 wp_redirect ($ this ->get_error_payment_url ($ order , $ message ));
10131043 die ();
10141044 }
0 commit comments