Skip to content

Commit 25ee9f7

Browse files
Merge pull request #4 from nofrixion/PLU19-make-merchantId-optional
removed merchantID from constructor, updated docs
2 parents 128eee6 + 379ae56 commit 25ee9f7

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,31 @@ composer require nofrixion/moneymoov-php
1717

1818
## Usage ##
1919

20-
The following example code shows how to use the library to create, updated and delete payment requests (see the [NoFrixion API documentation](https://docs.nofrixion.com/reference/sandbox) for a full MoneyMoov API reference and instructions on signing up for a sandbox account).
20+
The following example code shows how to use the library to create, update and delete payment requests (see the [NoFrixion API documentation](https://docs.nofrixion.com/reference/sandbox) for a full MoneyMoov API reference and instructions on signing up for a sandbox account).
2121

2222
```php
2323
// Client for handling Payment Request API endpoints
2424
use Nofrixion\Client\PaymentRequestClient;
25+
2526
// Models for creating/updating Payment Requests
2627
use Nofrixion\Model\PaymentRequests\PaymentRequestCreate;
2728
use Nofrixion\Model\PaymentRequests\PaymentRequestUpdate;
29+
2830
// Model returned by payment request client on creation/update
2931
use Nofrixion\Model\PaymentRequests\PaymentRequest;
3032

3133
use Nofrixion\Util\PreciseNumber;
3234

3335
$apiUrl = "https://api-sandbox.nofrixion.com/";
34-
// A merchant token is required for creating and modifying payment requests
36+
// A merchant token can be used for creating and modifying payment requests - this MUST be securely stored.
3537
$token = getenv("MERCHANT_TOKEN_SANDBOX");
3638

3739
$client = new PaymentRequestClient($apiUrl, $token);
3840

39-
// Creating a Payment request
40-
$merchID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
41+
// Creating a Payment request (payment amount is required).
4142
$amount = new PreciseNumber("1.11");
43+
$newPaymentRequest = new PaymentRequestCreate($amount->__toString());
4244

43-
// Required fields merchantID, amount, currency (default="EUR") and paymentMethodTypes (default="pisp") can be passed to the constructor.
44-
$newPaymentRequest = new PaymentRequestCreate($merchID, $amount->__toString());
4545
// Additional optional fields can be set directly on PaymentRequestCreate model.
4646
$newPaymentRequest->shippingFirstName = "Customer";
4747
$newPaymentRequest->shippingLastName = "Name";
@@ -51,14 +51,14 @@ $newPaymentRequest->baseOriginUrl = "https://store.example.com";
5151
$result = $client->createPaymentRequest($newPaymentRequest);
5252

5353

54-
// use the PaymentRequestUpdate model to update payment request values.
54+
// UPDATES: use the PaymentRequestUpdate model to update payment request values.
5555
$update = new PaymentRequestUpdate();
5656
$update->paymentMethodTypes = 'card, pisp';
5757
$update->amount = "1.45";
5858
$update->shippingAddressCity = "Dublin";
5959
$result = $client->updatePaymentRequest($result->id, $update);
6060

6161

62-
// Deleting a rayment request
62+
// DELETING a payment request
6363
$deleted = $client->deletePaymentRequest($result->id);
6464
```

src/Model/PaymentRequests/PaymentRequest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public function __construct(
9494
$this->addresses = $value;
9595
break;
9696
case "result":
97+
if (array_key_exists('customerID', $value)){
98+
$customerID = $value['customerID'];
99+
} else {
100+
$customerID = null;
101+
}
97102
$this->result = new PaymentRequestResult(
98103
$value['paymentRequestID'],
99104
$value['amount'],
@@ -102,7 +107,7 @@ public function __construct(
102107
$value['requestedAmount'],
103108
$value['payments'],
104109
$value['pispAuthorizations'],
105-
$value['customerID']
110+
$customerID
106111
);
107112
break;
108113
case "shippingAddress":

src/Model/PaymentRequests/PaymentRequestCreate.php

+8-15
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
use Nofrixion\Util\PreciseNumber;
88

99
/**
10-
* PaymentRequestCreate - use to create payment request, at minimum MerchantID, amount, currency and paymentMethodTypes
11-
* must be set in constructor. Other properties can be assigned direclty.
10+
* PaymentRequestCreate - use to create payment request.
11+
* `amount` must be set in constructor. Other properties can be assigned directly.
1212
*/
1313
class PaymentRequestCreate
1414
{
15-
public string $merchantID;
15+
public ?string $merchantID;
1616
public string $amount;
17-
public string $currency;
18-
public string $paymentMethodTypes;
19-
public ?string $CustomerID;
20-
public ?string $OrderID;
17+
public ?string $currency = null;
18+
public ?string $paymentMethodTypes;
19+
public ?string $customerID;
20+
public ?string $orderID;
2121
public ?string $description;
2222
public ?string $pispAccountID;
2323
public ?string $shippingFirstName;
@@ -55,16 +55,9 @@ class PaymentRequestCreate
5555
public ?array $tags;
5656

5757
public function __construct(
58-
string $merchantID,
59-
string $amount,
60-
string $currency = "EUR",
61-
string $paymentMethodTypes = "pisp"
58+
string $amount
6259
)
6360
{
64-
$this->merchantID = $merchantID;
6561
$this->amount = $amount;
66-
$this->currency = $currency;
67-
$this->paymentMethodTypes = $paymentMethodTypes;
68-
6962
}
7063
}

0 commit comments

Comments
 (0)