2
2
3
3
declare (strict_types=1 );
4
4
5
- namespace NoFrixion \Client ;
5
+ namespace Nofrixion \Client ;
6
6
7
- use NoFrixion \Util \PreciseNumber ;
7
+ use Nofrixion \Model \PaymentRequests \PaymentInitiationResponse ;
8
+ use Nofrixion \Util \PreciseNumber ;
8
9
9
- class PaymentRequest extends AbstractClient
10
+ class PaymentRequestClient extends AbstractClient
10
11
{
11
12
/**
12
13
* @see https://docs.nofrixion.com/reference/post_api-v1-paymentrequests
@@ -34,19 +35,19 @@ public function createPaymentRequest(
34
35
}
35
36
36
37
$ body = http_build_query ([
37
- 'Amount ' => $ amount ->__toString (),
38
- 'Currency ' => $ currency ,
39
- 'OriginUrl ' => $ originUrl ,
40
- 'CallbackUrl ' => $ callbackUrl ,
41
- 'PaymentMethodTypes ' => $ paymentMethodTypes ,
42
- 'OrderID ' => $ orderId ,
43
- 'CardCreateToken ' => $ createToken && $ customerEmailAddress != "" ? 'true ' : 'false ' ,
44
- 'CustomerID ' => $ customerId ?? '' ,
45
- 'CardAuthorizeOnly ' => $ cardAuthorizeOnly ? 'true ' : 'false ' ,
46
- 'CustomerEmailAddress ' => $ customerEmailAddress ,
47
- 'IgnoreAddressVerification ' => $ showBillingAddressSameAsShippingAddressCheckbox ? 'false ' : 'true ' ,
48
- 'SuccessWebHookUrl ' => $ successWebHookUrl
49
- ]);
38
+ 'Amount ' => $ amount ->__toString (),
39
+ 'Currency ' => $ currency ,
40
+ 'OriginUrl ' => $ originUrl ,
41
+ 'CallbackUrl ' => $ callbackUrl ,
42
+ 'PaymentMethodTypes ' => $ paymentMethodTypes ,
43
+ 'OrderID ' => $ orderId ,
44
+ 'CardCreateToken ' => $ createToken && $ customerEmailAddress != "" ? 'true ' : 'false ' ,
45
+ 'CustomerID ' => $ customerId ?? '' ,
46
+ 'CardAuthorizeOnly ' => $ cardAuthorizeOnly ? 'true ' : 'false ' ,
47
+ 'CustomerEmailAddress ' => $ customerEmailAddress ,
48
+ 'IgnoreAddressVerification ' => $ showBillingAddressSameAsShippingAddressCheckbox ? 'false ' : 'true ' ,
49
+ 'SuccessWebHookUrl ' => $ successWebHookUrl
50
+ ]);
50
51
51
52
$ response = $ this ->getHttpClient ()->request ($ method , $ url , $ headers , $ body );
52
53
@@ -57,6 +58,24 @@ public function createPaymentRequest(
57
58
}
58
59
}
59
60
61
+ /**
62
+ * @see https://docs.nofrixion.com/reference/delete_api-v1-paymentrequests-id
63
+ */
64
+ public function deletePaymentRequest (
65
+ string $ paymentRequestId
66
+ ): array {
67
+ $ url = $ this ->getApiUrl () . 'paymentrequests/ ' . urlencode ($ paymentRequestId );
68
+ $ headers = $ this ->getRequestHeaders ();
69
+ $ method = 'DELETE ' ;
70
+ $ response = $ this ->getHttpClient ()->request ($ method , $ url , $ headers );
71
+
72
+ if ($ response ->getStatus () === 200 ) {
73
+ return json_decode ($ response ->getBody (), true , 512 , JSON_THROW_ON_ERROR );
74
+ } else {
75
+ throw $ this ->getExceptionByStatusCode ($ method , $ url , $ response );
76
+ }
77
+ }
78
+
60
79
/**
61
80
* @see https://docs.nofrixion.com/reference/put_api-v1-paymentrequests-id
62
81
*/
@@ -78,17 +97,17 @@ public function updatePaymentRequest(
78
97
$ method = 'PUT ' ;
79
98
80
99
$ body = http_build_query ([
81
- 'Amount ' => $ amount ->__toString (),
82
- 'Currency ' => $ currency ,
83
- 'OriginUrl ' => $ originUrl ,
84
- 'CallbackUrl ' => $ callbackUrl ,
85
- 'PaymentMethodTypes ' => implode (', ' , $ paymentMethodTypes ),
86
- //'OrderID' => $orderId,
87
- 'CardCreateToken ' => $ createToken && $ customerEmailAddress !== "" && $ customerEmailAddress !== null ? 'true ' : 'false ' ,
88
- 'CustomerID ' => $ customerId ?? '' ,
89
- 'CardAuthorizeOnly ' => $ cardAuthorizeOnly ? 'true ' : 'false ' ,
90
- 'CustomerEmailAddress ' => $ customerEmailAddress
91
- ]);
100
+ 'Amount ' => $ amount ->__toString (),
101
+ 'Currency ' => $ currency ,
102
+ 'OriginUrl ' => $ originUrl ,
103
+ 'CallbackUrl ' => $ callbackUrl ,
104
+ 'PaymentMethodTypes ' => implode (', ' , $ paymentMethodTypes ),
105
+ //'OrderID' => $orderId,
106
+ 'CardCreateToken ' => $ createToken && $ customerEmailAddress !== "" && $ customerEmailAddress !== null ? 'true ' : 'false ' ,
107
+ 'CustomerID ' => $ customerId ?? '' ,
108
+ 'CardAuthorizeOnly ' => $ cardAuthorizeOnly ? 'true ' : 'false ' ,
109
+ 'CustomerEmailAddress ' => $ customerEmailAddress
110
+ ]);
92
111
93
112
$ response = $ this ->getHttpClient ()->request ($ method , $ url , $ headers , $ body );
94
113
@@ -154,6 +173,54 @@ public function getPaymentRequestResult(
154
173
}
155
174
}
156
175
176
+ /**
177
+ * initiatePayByBank - Submits a payment initiation request.
178
+ * @param string $paymentRequestId
179
+ * @param string $bankId
180
+ * @return \Nofrixion\Model\PaymentRequests\PaymentInitiationResponse
181
+ */
182
+ public function initiatePayByBank (
183
+ string $ paymentRequestId ,
184
+ string $ bankId ,
185
+ ?string $ redirectToOriginUrl ,
186
+ ?PreciseNumber $ amount
187
+ ): PaymentInitiationResponse {
188
+ $ url = $ this ->getApiUrl () . 'paymentrequests/ ' . urlencode ($ paymentRequestId ) . '/pisp ' ;
189
+ $ headers = $ this ->getRequestHeaders ();
190
+ $ method = 'POST ' ;
191
+ $ response = $ this ->getHttpClient ()->request ($ method , $ url , $ headers );
192
+
193
+ if (!is_null ($ amount )) {
194
+ $ amount = $ amount ->__toString ();
195
+ }
196
+ $ body = http_build_query ([
197
+ 'ProviderID ' => $ bankId ,
198
+ 'PartialAmount ' => $ amount ,
199
+ 'RedirectToOriginUrl ' => $ redirectToOriginUrl
200
+ ]);
201
+
202
+ $ response = $ this ->getHttpClient ()->request ($ method , $ url , $ headers , $ body );
203
+
204
+ if (in_array ($ response ->getStatus (), [200 , 201 ], true )) {
205
+ $ responseBody = json_decode ($ response ->getBody (), true , 512 , JSON_THROW_ON_ERROR );
206
+ // return json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);
207
+
208
+ $ paymentInitiationResponse = new PaymentInitiationResponse ();
209
+
210
+ $ paymentInitiationResponse ->paymentRequestID = $ responseBody ['paymentRequestID ' ];
211
+ $ paymentInitiationResponse ->responseType = $ responseBody ['responseType ' ];
212
+ $ paymentInitiationResponse ->paymentInitiationId = $ responseBody ['paymentInitiationID ' ] ?? null ;
213
+ $ paymentInitiationResponse ->paymentRequestCallbackUrl = $ responseBody ['paymentRequestCallbackUrl ' ] ?? null ;
214
+ $ paymentInitiationResponse ->plaidLinkToken = $ responseBody ['plaidLinkToken ' ] ?? null ;
215
+ $ paymentInitiationResponse ->redirectUrl = $ responseBody ['redirectUrl ' ] ?? null ;
216
+ $ paymentInitiationResponse ->specificErrorMessage = $ responseBody ['specificErrorMessage ' ] ?? null ;
217
+
218
+ return $ paymentInitiationResponse ;
219
+ } else {
220
+ throw $ this ->getExceptionByStatusCode ($ method , $ url , $ response );
221
+ }
222
+ }
223
+
157
224
/**
158
225
* @see https://docs.nofrixion.com/reference/post_api-v1-paymentrequests-id-card-paywithtoken
159
226
*/
@@ -166,8 +233,8 @@ public function payWithCardToken(
166
233
$ method = 'POST ' ;
167
234
168
235
$ body = http_build_query ([
169
- 'TokenisedCardID ' => $ tokenisedCardId
170
- ]);
236
+ 'TokenisedCardID ' => $ tokenisedCardId
237
+ ]);
171
238
172
239
$ response = $ this ->getHttpClient ()->request ($ method , $ url , $ headers , $ body );
173
240
@@ -197,6 +264,7 @@ public function getCustomerTokenisedCards(string $customerId): array
197
264
198
265
/**
199
266
* @see https://docs.nofrixion.com/reference/post_api-v1-paymentrequests-id-pisp
267
+ * @deprecated 2.0.0 No longer used by internal code and not recommended.
200
268
*/
201
269
public function submitPaymentInitiationRequest (
202
270
string $ paymentRequestId ,
@@ -207,8 +275,8 @@ public function submitPaymentInitiationRequest(
207
275
$ method = 'POST ' ;
208
276
209
277
$ body = http_build_query ([
210
- 'ProviderID ' => $ providerId
211
- ]);
278
+ 'ProviderID ' => $ providerId
279
+ ]);
212
280
213
281
$ response = $ this ->getHttpClient ()->request ($ method , $ url , $ headers , $ body );
214
282
@@ -237,4 +305,4 @@ public function voidAllPaymentsForPaymentRequest(string $paymentRequestId): arra
237
305
throw $ this ->getExceptionByStatusCode ($ method , $ url , $ response );
238
306
}
239
307
}
240
- }
308
+ }
0 commit comments