@@ -16,7 +16,6 @@ public function execute()
16
16
$ orderIds = explode ("- " , $ rawOrderIds );
17
17
18
18
$ transactionAmount = 0 ;
19
- $ incrementIds = [];
20
19
$ tokenId = '' ;
21
20
$ orders = [];
22
21
@@ -41,42 +40,40 @@ public function execute()
41
40
}
42
41
43
42
$ transactionAmount += (int )$ order ->getTotalDue ();
44
- $ incrementIds [] = $ order ->getIncrementId ();
45
43
}
46
44
47
45
if ($ method === 'cc ' ) {
48
- $ externalIdSuffix = implode ("- " , $ incrementIds );
49
46
$ requestData = array (
50
47
'token_id ' => $ tokenId ,
51
48
'card_cvn ' => $ cvn ,
52
49
'amount ' => $ transactionAmount ,
53
- 'external_id ' => $ this ->getDataHelper ()->getExternalId ($ externalIdSuffix ),
54
- 'return_url ' => $ this ->getDataHelper ()->getThreeDSResultUrl ($ externalIdSuffix )
50
+ 'external_id ' => $ this ->getDataHelper ()->getExternalId ($ rawOrderIds ),
51
+ 'return_url ' => $ this ->getDataHelper ()->getThreeDSResultUrl ($ rawOrderIds , true )
55
52
);
56
53
57
54
$ charge = $ this ->requestCharge ($ requestData );
58
55
59
56
$ chargeError = isset ($ charge ['error_code ' ]) ? $ charge ['error_code ' ] : null ;
60
57
if ($ chargeError == 'EXTERNAL_ID_ALREADY_USED_ERROR ' ) {
61
58
$ newRequestData = array_replace ($ requestData , array (
62
- 'external_id ' => $ this ->getDataHelper ()->getExternalId ($ externalIdSuffix , true )
59
+ 'external_id ' => $ this ->getDataHelper ()->getExternalId ($ rawOrderIds , true )
63
60
));
64
61
$ charge = $ this ->requestCharge ($ newRequestData );
65
62
}
66
63
67
64
$ chargeError = isset ($ charge ['error_code ' ]) ? $ charge ['error_code ' ] : null ;
68
65
if ($ chargeError == 'AUTHENTICATION_ID_MISSING_ERROR ' ) {
69
- return $ this ->handle3DSFlow ($ requestData , $ payment , $ incrementIds , $ orders );
66
+ return $ this ->handle3DSFlow ($ requestData , $ payment , $ orderIds , $ orders );
70
67
}
71
68
72
69
if ($ chargeError !== null ) {
73
- return $ this ->processFailedPayment ($ incrementIds , $ chargeError );
70
+ return $ this ->processFailedPayment ($ orderIds , $ chargeError );
74
71
}
75
72
76
73
if ($ charge ['status ' ] === 'CAPTURED ' ) {
77
74
return $ this ->processSuccessfulPayment ($ orders , $ payment , $ charge );
78
75
} else {
79
- return $ this ->processFailedPayment ($ incrementIds , $ charge ['failure_reason ' ]);
76
+ return $ this ->processFailedPayment ($ orderIds , $ charge ['failure_reason ' ]);
80
77
}
81
78
}
82
79
else if ($ method === 'cchosted ' ) {
@@ -87,7 +84,7 @@ public function execute()
87
84
'store_name ' => $ this ->getStoreManager ()->getStore ()->getName (),
88
85
'platform_name ' => 'MAGENTO2 ' ,
89
86
'success_redirect_url ' => $ this ->getDataHelper ()->getSuccessUrl (true ),
90
- 'failure_redirect_url ' => $ this ->getDataHelper ()->getFailureUrl ($ rawOrderIds ),
87
+ 'failure_redirect_url ' => $ this ->getDataHelper ()->getFailureUrl ($ rawOrderIds, true ),
91
88
'platform_callback_url ' => $ this ->_url ->getUrl ('xendit/checkout/cccallback ' ) . '?order_ids= ' . $ rawOrderIds
92
89
];
93
90
@@ -96,7 +93,7 @@ public function execute()
96
93
if (isset ($ hostedPayment ['error_code ' ])) {
97
94
$ message = isset ($ hostedPayment ['message ' ]) ? $ hostedPayment ['message ' ] : $ hostedPayment ['error_code ' ];
98
95
99
- return $ this ->processFailedPayment ($ incrementIds , $ message );
96
+ return $ this ->processFailedPayment ($ orderIds , $ message );
100
97
} else if (isset ($ hostedPayment ['id ' ])) {
101
98
$ hostedPaymentId = $ hostedPayment ['id ' ];
102
99
$ hostedPaymentToken = $ hostedPayment ['hp_token ' ];
@@ -112,7 +109,7 @@ public function execute()
112
109
} else {
113
110
$ message = 'Error connecting to Xendit. Please check your API key. ' ;
114
111
115
- return $ this ->processFailedPayment ($ incrementIds , $ message );
112
+ return $ this ->processFailedPayment ($ orderIds , $ message );
116
113
}
117
114
}
118
115
} catch (\Exception $ e ) {
@@ -163,6 +160,9 @@ private function addCCHostedData($orders, $data)
163
160
}
164
161
}
165
162
163
+ /**
164
+ * $orderIds = prefixless order IDs
165
+ */
166
166
private function handle3DSFlow ($ requestData , $ payment , $ orderIds , $ orders )
167
167
{
168
168
unset($ requestData ['card_cvn ' ]);
@@ -183,9 +183,9 @@ private function handle3DSFlow($requestData, $payment, $orderIds, $orders)
183
183
$ payment ->setAdditionalInformation ('xendit_hosted_3ds_id ' , $ hostedId );
184
184
185
185
foreach ($ orderIds as $ key => $ value ) {
186
- $ order = $ this ->getOrderById ( $ value );
187
-
188
- $ order ->addStatusHistoryComment ("Xendit payment waiting for authentication. 3DS id : $ hostedId " );
186
+ $ order = $ this ->getOrderFactory ()-> create ( );
187
+ $ order -> load ( $ value );
188
+ $ order ->addStatusHistoryComment ("Xendit payment waiting for authentication. 3DS ID : $ hostedId " );
189
189
$ order ->save ();
190
190
}
191
191
@@ -210,6 +210,9 @@ private function handle3DSFlow($requestData, $payment, $orderIds, $orders)
210
210
return $ this ->processFailedPayment ($ orderIds );
211
211
}
212
212
213
+ /**
214
+ * $orderIds = prefixless order IDs
215
+ */
213
216
private function processFailedPayment ($ orderIds , $ failureReason = 'Unexpected Error with empty charge ' )
214
217
{
215
218
$ this ->getCheckoutHelper ()->processOrdersFailedPayment ($ orderIds , $ failureReason );
0 commit comments