Skip to content

Commit 40accbc

Browse files
committed
Merge remote-tracking branch 'github/v3.x' into 6254-api-endpoints-v2
2 parents a0a7f17 + eb77513 commit 40accbc

File tree

4 files changed

+104
-79
lines changed

4 files changed

+104
-79
lines changed

doc/refund-payment.md

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,45 @@
1-
# Refund payment
1+
# Refund Payment
22

3-
Most paid payments can be automatically refund to customer, call createPaymentRefund($uid, $amount, $reason).
3+
Most paid payments can be automatically refunded back to the customer.
4+
To create a refund, call `createPaymentRefund($uid, $amount, $reason)`.
45

5-
Detect if payment is refundable by call getPaymentRefund($uid)->getAvailableAmount() !== 0.
6+
You can check whether a payment is refundable by inspecting the available refundable amount:
67

7-
A refunded amount can be smaller than availableAmount for payment but cannot be bigger,
8-
for one payment can be created multiple refunds.
8+
```php
9+
$available = $thePayClient->getPaymentRefund($uid)->getAvailableAmount();
10+
$isRefundable = ($available !== 0);
11+
```
12+
13+
A refund can be **partial** or **full**:
14+
- You may refund less than the available amount
15+
- You may not refund more than the available amount
16+
- You may create multiple refunds for one payment, as long as sufficient refundable amount remains
917

10-
Basic load information about payment refund,
18+
## Loading Refund Information
1119

12-
after client call can be rendered information about refund how you like,
13-
or refund form can be rendered if some amount for refund is available.
20+
You can load the refund information for a payment and render it however you prefer—either as details for the user or to display a refund form when a refund is possible.
1421

1522
```php
1623
/** @var \ThePay\ApiClient\TheClient $thePayClient */
1724
$paymentRefundInfo = $thePayClient->getPaymentRefund('uid-454548');
1825
```
1926

20-
Recommended refund action processing,
27+
## Recommended Refund Processing Flow
2128

22-
always check if refunded amount is available to avoid 403 api exception
23-
and if not available render some message for user
29+
Before creating a refund, always verify that the requested refund amount is still available.
30+
This prevents a `403` API exception and allows you to show a meaningful message to the user.
2431

2532
```php
2633
/** @var \ThePay\ApiClient\TheClient $thePayClient */
27-
if($thePayClient->getPaymentRefund('uid-454548')->getAvailableAmount() >= 10000) {
28-
$thePayClient->createPaymentRefund('uid-454548', 10000, 'Partial refund because some items was delivered broken');
34+
$refundInfo = $thePayClient->getPaymentRefund('uid-454548');
35+
36+
if ($refundInfo->getAvailableAmount() >= 10000) {
37+
$thePayClient->createPaymentRefund(
38+
'uid-454548',
39+
10000,
40+
'Partial refund because some items were delivered broken'
41+
);
42+
} else {
43+
// Render message: refund amount is not available
2944
}
3045
```

doc/return-of-the-customer.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
# Return of the Customer
22

3-
After payment creation, you will have to wait to return of the customer, keep in mind:
3+
After you create a payment, you redirect the customer to the payment gateway using the URL provided.
4+
Once the customer finishes (or abandons) the process at the gateway, they may be redirected back to your website.
45

5-
- the customer may not return to your website
6-
- the payment may not be paid in the moment of the return
6+
Keep in mind:
7+
- The customer may **not** return to your website
8+
- The payment may **not** be paid at the moment they return
79

8-
The customer will be returned to url specified in administration (in the project settings):
10+
## Configuring the Return URL
911

10-
![settings](img/settings.png)
12+
- The customer will be returned to url specified in administration (in the project settings):
1113

12-
This value may be overridden for each payment in CreatePaymentParams by setReturnUrl() function.
14+
![settings](img/settings.png)
1315

14-
There are two query parameters added to redirect url:
16+
You can override this value on a per-payment basis in `CreatePaymentParams` using the `setReturnUrl()` method.
1517

16-
* payment_uid
17-
* project_id
18+
## Return URL Parameters
1819

19-
In most cases you want to check the state of payment after customer's return:
20+
When the customer is redirected back, the following query parameters are appended:
21+
- payment_uid
22+
- project_id
2023

21-
[See how to make TheClient](../.github/README.md#theclient-instance)
24+
You can use these identifiers to load the current state of the payment:
2225

2326
```php
24-
2527
$uid = $_GET["payment_uid"];
2628
$projectId = $_GET["project_id"];
2729

doc/saving-authorization.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,48 @@
1-
# Saving card authorization
1+
# Saving Card Authorization
22

3-
It is possible to remember customer card information by using the save_authorization parameter upon payment creation.This allow easier and seamless payment creation, through following child payments, without additional customer card authorization.It shoud however NOT be confused with (and used for) [subscription payments](subscription.md).
3+
It is possible to store a customer’s card authorization by enabling the `save_authorization` parameter when creating a payment.
4+
This allows you to create follow-up (“child”) payments seamlessly, without requiring the customer to reauthorize their card.
45

5-
## Creating payment with save_authorization flag
6+
However, this feature must not be confused with — or used for — [subscription payments](subscription.md). Those have a separate workflow and rules.
7+
8+
## Creating a Payment with `save_authorization`
69

710
```php
811

912
/** @var \ThePay\ApiClient\TheClient $thePayClient */
1013

11-
$createPayment = new \ThePay\ApiClient\Model\CreatePaymentParams(10520, 'EUR', 'savedauthtest');
14+
$createPayment = new \ThePay\ApiClient\Model\CreatePaymentParams(10520, 'EUR', 'uid_savedauthtest', $customer);
1215

13-
// set save_authorization to true
16+
// Enable saving of card authorization
1417
$createPayment->setSaveAuthorization(true);
1518

1619
$payment = $thePayClient->createPayment($createPayment);
1720

18-
// Get url where user can pay
21+
// Redirect customer to this URL to complete the payment
1922
echo $payment->getPayUrl(); // https://demo.gate.thepay.cz/5aa4f4af546a74848/pay/
2023
```
2124

22-
## Realizing new payment by saved authorization
25+
Once the payment is successfully completed, the system will store a reusable authorization token associated with the payment.
26+
27+
## Creating a New Payment Using Saved Authorization
2328

24-
After the created payment was paid, we can realize new payment by saved authorization:
29+
After the original payment (with `save_authorization = true`) has been paid, you can realize a new payment using the stored authorization:
2530

2631
```php
2732
/** @var \ThePay\ApiClient\TheClient $thePayClient */
2833

29-
// V2 API requires amount and currency code
30-
// first parameter is uid of new (child) payment
31-
// second parameter contains amount in cents (required)
32-
// third parameter contains currency code (required)
34+
// First parameter: UID of the new (child) payment
35+
// Second parameter: amount in cents (required)
36+
// Third parameter: currency code (required)
3337
$params = new \ThePay\ApiClient\Model\RealizePaymentBySavedAuthorizationParams('childpayment', 1000, 'EUR');
3438

3539
// adding items is optional, if you do not add any item, items from parent payment will be used
3640
$item = new \ThePay\ApiClient\Model\CreatePaymentItem('item', 'Server setup', 1000, 1);
3741
$params->addItem($item);
3842

39-
40-
// first parameter is uid of parent payment (the one we create above with savedAuthorization set to true).
41-
// method will return ApiResponse
42-
$response = $thePayClient->realizePaymentBySavedAuthorization('savedauthtest', $params);
43+
// First parameter: UID of the parent payment (one created with saveAuthorization=true)
44+
// The method returns ApiResponse
45+
$response = $thePayClient->realizePaymentBySavedAuthorization('uid_savedauthtest', $params);
4346

4447
if ($response->wasSuccessful()) {
4548
echo 'Payment was realized using saved authorization';

doc/subscription.md

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,63 @@
1-
# Subscription payments
1+
# Subscription Payments
22

3-
It is possible to create long term subscription for your customers. The setup for subsription is done through regular endpoint for payment creation, but with the subscription properties set. The payment created can then be repeatedly paid by the customer, through a different endpoint.
3+
Subscription payments allow you to charge a customer repeatedly over time.
4+
A subscription is initialized through a standard payment creation request, but with subscription properties attached.
5+
Once the initial (parent) payment is completed, follow-up (child) payments can be realized using dedicated subscription endpoints.
46

5-
There are three different use cases with different endpoints for subscription payments, depending on payment time and payment amount needs.
6-
* Fixed time interval & fixed payment amount
7-
* Variable time interval & fixed payment amount
8-
* Fixed time interval & variable payment amount
7+
There are three main subscription types, depending on whether the time interval and payment amount are fixed or variable:
8+
- Fixed time interval & fixed amount
9+
- Variable time interval & fixed amount
10+
- Fixed time interval & variable amount
911

10-
The time interval or amount with fixed value is always set in the first (parent) payment upon payment creation. It is your responsibility to adhere to the values set in the parent payment. If you need to change the fixed payment amount or time period, a new subscription payment with different parameters must be used.
12+
Any value marked as fixed must be set in the parent payment, and it is your responsibility to adhere to it when creating child payments.
13+
If your subscription requires a different amount or interval, you must create a new parent subscription payment.
1114

12-
**RECURRING PAYMENTS MUST BE ENABLED ON PROJECT**
15+
⚠️ **Important / Prerequisites**
16+
- **Recurring payments must be enabled on your project**.
1317

14-
## Creating payment with subscription properties
18+
19+
## Creating a Payment with Subscription Properties
1520

1621
```php
1722
/** @var \ThePay\ApiClient\TheClient $thePayClient */
1823

19-
// prepare subscription properties (first parameter is type, second parameter is day period between payments)
24+
// Prepare subscription properties:
25+
// First parameter: subscription type
26+
// Second parameter: number of days between payments (for fixed interval types)
2027
$subscription = new \ThePay\ApiClient\Model\Subscription(
2128
\ThePay\ApiClient\ValueObject\SubscriptionType::REGULAR,
2229
30
2330
);
2431

25-
// Create payment (105.20 € with unique id 'subscriptionpayment')
26-
$createPayment = new \ThePay\ApiClient\Model\CreatePaymentParams(10520, 'EUR', 'subscriptionpayment');
32+
// Create initial subscription payment (105.20 € with UID 'uid_subscriptionpayment')
33+
$createPayment = new \ThePay\ApiClient\Model\CreatePaymentParams(10520, 'EUR', 'uid_subscriptionpayment', $customer);
2734
$createPayment->setSubscription($subscription);
2835

2936
$payment = $thePayClient->createPayment($createPayment);
3037

31-
// Get url where user can pay
38+
// Redirect the customer to complete the payment
3239
echo $payment->getPayUrl(); // https://demo.gate.thepay.cz/5aa4f4af546a74848/pay/
3340
```
3441

3542
## Realizing subscription payment
3643

37-
After the created payment was paid, we can realize subscription:
44+
After the parent payment is paid, you may charge the customer again using one of the three subscription realization types.
3845

39-
### Realizing regular subscription payment type
46+
### Realizing a Regular (Fixed Interval & Fixed Amount) Subscription
4047

4148
```php
4249
/** @var \ThePay\ApiClient\TheClient $thePayClient */
4350

44-
// parameter is uid of new (child) payment
45-
$params = new \ThePay\ApiClient\Model\RealizeRegularSubscriptionPaymentParams('childpayment');
51+
// UID of the new (child) payment
52+
$params = new \ThePay\ApiClient\Model\RealizeRegularSubscriptionPaymentParams('uid_childpayment');
4653

47-
// adding items is optional, if you do not add any item, items from parent payment will be used
54+
// You may optionally define items. If omitted, items from parent payment are reused.
4855
$item = new \ThePay\ApiClient\Model\CreatePaymentItem('item', 'Magazine #2', 10520, 1);
4956
$params->addItem($item);
5057

51-
52-
// first parameter is uid of parent payment (the one we create above with subscription property).
53-
// method will return ApiResponse
54-
$response = $thePayClient->realizeRegularSubscriptionPayment('subscriptionpayment', $params);
58+
// Parent payment UID is passed as the first parameter.
59+
// Method returns an ApiResponse.
60+
$response = $thePayClient->realizeRegularSubscriptionPayment('uid_subscriptionpayment', $params);
5561

5662
if ($response->wasSuccessful()) {
5763
echo 'Subscription payment was realized';
@@ -76,22 +82,21 @@ The V2 API supports asynchronous payment processing:
7682
- You will receive a notification when the async payment completes (state changes to `paid` or `error`)
7783
- Always check `parent.recurring_payments_available` to know if the subscription should end
7884

79-
### Realizing irregular subscription payment type
85+
### Realizing an Irregular (Variable Interval & Fixed Amount) Subscription
8086

8187
```php
8288
/** @var \ThePay\ApiClient\TheClient $thePayClient */
8389

84-
// parameter is uid of new (child) payment
85-
$params = new \ThePay\ApiClient\Model\RealizeIrregularSubscriptionPaymentParams('childpayment2');
90+
// UID of the new (child) payment
91+
$params = new \ThePay\ApiClient\Model\RealizeIrregularSubscriptionPaymentParams('uid_childpayment2');
8692

87-
// adding items is optional, if you do not add any item, items from parent payment will be used
93+
// You may optionally define items. If omitted, items from parent payment are reused.
8894
$item = new \ThePay\ApiClient\Model\CreatePaymentItem('item', 'New book', 10520, 1);
8995
$params->addItem($item);
9096

91-
92-
// first parameter is uid of parent payment (the one we create above with subscription property).
93-
// method will return ApiResponse
94-
$response = $thePayClient->realizeIrregularSubscriptionPayment('subscriptionpayment', $params);
97+
// Parent payment UID is passed as the first parameter.
98+
// Method returns an ApiResponse.
99+
$response = $thePayClient->realizeIrregularSubscriptionPayment('uid_subscriptionpayment', $params);
95100

96101
if ($response->wasSuccessful()) {
97102
echo 'Subscription payment was realized';
@@ -105,23 +110,23 @@ if ($response->isRecurringPaymentsAvailable() === false) {
105110
}
106111
```
107112

108-
### Realizing usage based subscription payment type
113+
### Realizing a Usage-Based (Fixed Interval & Variable Amount) Subscription
109114

110115
```php
111116
/** @var \ThePay\ApiClient\TheClient $thePayClient */
112117

113-
// first parameter is uid of new (child) payment
114-
// second parameter is amount in cents (in parent payment currency)
115-
$params = new \ThePay\ApiClient\Model\RealizeUsageBasedSubscriptionPaymentParams('childpayment3', 18000);
118+
// First param: UID of child payment
119+
// Second param: amount in cents (in the parent payment currency)
120+
$params = new \ThePay\ApiClient\Model\RealizeUsageBasedSubscriptionPaymentParams('uid_childpayment3', 18000);
116121

117-
// adding items is optional, if you do not add any item, items from parent payment will be used
122+
// You may optionally define items. If omitted, items from parent payment are reused.
118123
$item = new \ThePay\ApiClient\Model\CreatePaymentItem('item', 'Server usage', 18000, 1);
119124
$params->addItem($item);
120125

121126

122-
// first parameter is uid of parent payment (the one we create above with subscription property).
123-
// method will return ApiResponse
124-
$response = $thePayClient->realizeUsageBasedSubscriptionPayment('subscriptionpayment', $params);
127+
// Parent payment UID is passed as the first parameter.
128+
// Method returns an ApiResponse.
129+
$response = $thePayClient->realizeUsageBasedSubscriptionPayment('uid_subscriptionpayment', $params);
125130

126131
if ($response->wasSuccessful()) {
127132
echo 'Subscription payment was realized';

0 commit comments

Comments
 (0)