Skip to content

Commit e6a5e7a

Browse files
Merge pull request #2 from nofrixion/feature-pisp-initiate
Feature pisp initiate
2 parents ee89e6c + de252b3 commit e6a5e7a

21 files changed

+610
-73
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/.idea
2-
/vendor
2+
/vendor
3+
/test
4+
*.code-workspace

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "MIT",
66
"autoload": {
77
"psr-4": {
8-
"NoFrixion\\": "src/"
8+
"Nofrixion\\": "src/"
99
}
1010
},
1111
"authors": [

Diff for: src/Client/AbstractClient.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
declare(strict_types=1);
44

5-
namespace NoFrixion\Client;
5+
namespace Nofrixion\Client;
66

7-
use NoFrixion\Exception\BadRequestException;
8-
use NoFrixion\Exception\ForbiddenException;
9-
use NoFrixion\Exception\RequestException;
10-
use NoFrixion\Http\ClientInterface;
11-
use NoFrixion\Http\CurlClient;
12-
use NoFrixion\Http\Response;
7+
use Nofrixion\Exception\BadRequestException;
8+
use Nofrixion\Exception\ForbiddenException;
9+
use Nofrixion\Exception\RequestException;
10+
use Nofrixion\Exception\NofrixionException;
11+
use Nofrixion\Http\ClientInterface;
12+
use Nofrixion\Http\CurlClient;
13+
use Nofrixion\Http\Response;
1314

1415
class AbstractClient
1516
{

Diff for: src/Client/MerchantClient.php

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Nofrixion\Client;
6+
7+
use Nofrixion\Model\Merchant\Merchant;
8+
use Nofrixion\Model\Merchant\MerchantPayByBankSetting;
9+
use \RuntimeException;
10+
11+
12+
/**
13+
* MerchantClient enables calls to MoneyMoov API `merchant/` endpoints
14+
*/
15+
class MerchantClient extends AbstractClient
16+
{
17+
18+
/**
19+
* getMerchantPayByBankSettings returns an array of MerchantPayByBankSetting objects.
20+
* @param string $merchantId
21+
* @return array
22+
*/
23+
public function getMerchantPayByBankSettings(string $merchantId): array
24+
{
25+
$url = $this->getApiUrl() . 'merchants/' . $merchantId . '/banksettings';
26+
$headers = $this->getRequestHeaders();
27+
$method = 'GET';
28+
29+
$response = $this->getHttpClient()->request($method, $url, $headers);
30+
31+
if ($response->getStatus() === 200) {
32+
// $response contains the merchantId and an array of associative arrays, each one representing a Pay by bank setting.
33+
$response = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);
34+
$payByBankSettingsArray = array();
35+
36+
foreach ($response['payByBankSettings'] as $pisp) {
37+
$payByBankSetting = new MerchantPayByBankSetting(
38+
$pisp['bankID'],
39+
$pisp['bankName'] ?? null,
40+
$pisp['order'],
41+
$pisp['logo'] ?? null,
42+
$pisp['currency'],
43+
$pisp['processor'] ?? null,
44+
$pisp['personalInstitutionID'] ?? null,
45+
$pisp['businessInstitutionID'] ?? null,
46+
$pisp['message'] ?? null,
47+
$pisp['messageImageUrl'] ?? null
48+
);
49+
array_push($payByBankSettingsArray, $payByBankSetting);
50+
}
51+
// $merchantPayByBankSettings = new MerchantPayByBankSettings(
52+
// $response['merchantID'],
53+
// $payByBankSettingsArray
54+
// );
55+
return $payByBankSettingsArray;
56+
} else {
57+
throw $this->getExceptionByStatusCode($method, $url, $response);
58+
}
59+
}
60+
/**
61+
* whoAmIMerchant returns details of the merchant that was issued the API token used in the request.
62+
* @return \Nofrixion\Model\Merchant\Merchant
63+
*/
64+
public function whoAmIMerchant(): Merchant
65+
{
66+
$url = $this->getApiUrl() . 'metadata/whoamimerchant';
67+
$headers = $this->getRequestHeaders();
68+
$method = 'GET';
69+
// $webhookArray = array();
70+
71+
$response = $this->getHttpClient()->request($method, $url, $headers);
72+
73+
if ($response->getStatus() === 200) {
74+
// $response is an associative array representing the merchant.
75+
$responseBody = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);
76+
$merchant = new Merchant(
77+
$responseBody['id'],
78+
$responseBody['name'] ?? null,
79+
$responseBody['enabled'],
80+
$responseBody['companyId'] ?? null,
81+
$responseBody['merchantCategoryCode'],
82+
$responseBody['shortName'] ?? null,
83+
$responseBody['tradingName'] ?? null,
84+
$responseBody['paymentAccountLimit'],
85+
$responseBody['inserted'],
86+
$responseBody['jurisdiction'],
87+
$responseBody['hostedPayVersion'],
88+
$responseBody['webhookLimit'] ?? null,
89+
$responseBody['displayQrOnHostedPay'],
90+
$responseBody['yourRole'],
91+
$responseBody['userRoles'],
92+
$responseBody['tags'],
93+
$responseBody['paymentAccounts']
94+
);
95+
return $merchant;
96+
} else {
97+
throw $this->getExceptionByStatusCode($method, $url, $response);
98+
}
99+
}
100+
101+
}
102+
103+
//EOF

Diff for: src/Client/PaymentRequest.php renamed to src/Client/PaymentRequestClient.php

+100-32
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace NoFrixion\Client;
5+
namespace Nofrixion\Client;
66

7-
use NoFrixion\Util\PreciseNumber;
7+
use Nofrixion\Model\PaymentRequests\PaymentInitiationResponse;
8+
use Nofrixion\Util\PreciseNumber;
89

9-
class PaymentRequest extends AbstractClient
10+
class PaymentRequestClient extends AbstractClient
1011
{
1112
/**
1213
* @see https://docs.nofrixion.com/reference/post_api-v1-paymentrequests
@@ -34,19 +35,19 @@ public function createPaymentRequest(
3435
}
3536

3637
$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+
]);
5051

5152
$response = $this->getHttpClient()->request($method, $url, $headers, $body);
5253

@@ -57,6 +58,24 @@ public function createPaymentRequest(
5758
}
5859
}
5960

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+
6079
/**
6180
* @see https://docs.nofrixion.com/reference/put_api-v1-paymentrequests-id
6281
*/
@@ -78,17 +97,17 @@ public function updatePaymentRequest(
7897
$method = 'PUT';
7998

8099
$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+
]);
92111

93112
$response = $this->getHttpClient()->request($method, $url, $headers, $body);
94113

@@ -154,6 +173,54 @@ public function getPaymentRequestResult(
154173
}
155174
}
156175

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+
157224
/**
158225
* @see https://docs.nofrixion.com/reference/post_api-v1-paymentrequests-id-card-paywithtoken
159226
*/
@@ -166,8 +233,8 @@ public function payWithCardToken(
166233
$method = 'POST';
167234

168235
$body = http_build_query([
169-
'TokenisedCardID' => $tokenisedCardId
170-
]);
236+
'TokenisedCardID' => $tokenisedCardId
237+
]);
171238

172239
$response = $this->getHttpClient()->request($method, $url, $headers, $body);
173240

@@ -197,6 +264,7 @@ public function getCustomerTokenisedCards(string $customerId): array
197264

198265
/**
199266
* @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.
200268
*/
201269
public function submitPaymentInitiationRequest(
202270
string $paymentRequestId,
@@ -207,8 +275,8 @@ public function submitPaymentInitiationRequest(
207275
$method = 'POST';
208276

209277
$body = http_build_query([
210-
'ProviderID' => $providerId
211-
]);
278+
'ProviderID' => $providerId
279+
]);
212280

213281
$response = $this->getHttpClient()->request($method, $url, $headers, $body);
214282

@@ -237,4 +305,4 @@ public function voidAllPaymentsForPaymentRequest(string $paymentRequestId): arra
237305
throw $this->getExceptionByStatusCode($method, $url, $response);
238306
}
239307
}
240-
}
308+
}

Diff for: src/Client/WebhookClient.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
declare(strict_types=1);
44

5-
namespace NoFrixion\Client;
5+
namespace Nofrixion\Client;
66

7-
use NoFrixion\Client\AbstractClient;
8-
use NoFrixion\Model\Webhook;
7+
use Nofrixion\Client\AbstractClient;
8+
use Nofrixion\Model\Webhook;
99
use \RuntimeException;
1010

1111
/**

Diff for: src/Exception/BadRequestException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace NoFrixion\Exception;
5+
namespace Nofrixion\Exception;
66

77
class BadRequestException extends RequestException
88
{

Diff for: src/Exception/ConnectException.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
declare(strict_types=1);
44

5-
namespace NoFrixion\Exception;
5+
namespace Nofrixion\Exception;
66

7-
class ConnectException extends NoFrixionException
7+
use Nofrixion\Exception\NofrixionException;
8+
9+
class ConnectException extends NofrixionException
810
{
911
public function __construct(string $curlErrorMessage, int $curlErrorCode)
1012
{

Diff for: src/Exception/ForbiddenException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace NoFrixion\Exception;
5+
namespace Nofrixion\Exception;
66

77
class ForbiddenException extends RequestException
88
{

Diff for: src/Exception/NoFrixionException.php

-13
This file was deleted.

0 commit comments

Comments
 (0)