Skip to content

Commit eb77513

Browse files
authored
Merge pull request #99 from ThePay/6296-refunds-return-authorization-subscription
Documentation 3.0 - Refunds, customer return, saving authorization, s…
2 parents b09c434 + eff3284 commit eb77513

File tree

4 files changed

+105
-79
lines changed

4 files changed

+105
-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: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +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-
// first parameter is uid of new (child) payment
30-
// second parameter contains amount in cents, if sets to null it will use amount of parent payment, required if third parameter is set
31-
// third parameter contains currency code, if sets to null it will use currency code of parent payment, required if second parameter is set
32-
$params = new \ThePay\ApiClient\Model\RealizePaymentBySavedAuthorizationParams('childpayment', 1000, 'EUR');
34+
// First parameter: UID of the new (child) payment
35+
// Second parameter: amount in cents (optional; if null, parent amount is used; required if currency is set)
36+
// Third parameter: currency code (optional; if null, parent currency is used; required if amount is set)
37+
$params = new \ThePay\ApiClient\Model\RealizePaymentBySavedAuthorizationParams('uid_childpayment', 1000, 'EUR');
3338

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

38-
39-
// first parameter is uid of parent payment (the one we create above with savedAuthorization set to true).
40-
// method will return ApiResponse
41-
$response = $thePayClient->realizePaymentBySavedAuthorization('subscriptionpayment', $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);
4246

4347
if ($response->wasSuccessful()) {
4448
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,102 +1,107 @@
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';
5864
}
5965
```
6066

61-
### Realizing irregular subscription payment type
67+
### Realizing an Irregular (Variable Interval & Fixed Amount) Subscription
6268

6369
```php
6470
/** @var \ThePay\ApiClient\TheClient $thePayClient */
6571

66-
// parameter is uid of new (child) payment
67-
$params = new \ThePay\ApiClient\Model\RealizeIrregularSubscriptionPaymentParams('childpayment2');
72+
// UID of the new (child) payment
73+
$params = new \ThePay\ApiClient\Model\RealizeIrregularSubscriptionPaymentParams('uid_childpayment2');
6874

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

73-
74-
// first parameter is uid of parent payment (the one we create above with subscription property).
75-
// method will return ApiResponse
76-
$response = $thePayClient->realizeIrregularSubscriptionPayment('subscriptionpayment', $params);
79+
// Parent payment UID is passed as the first parameter.
80+
// Method returns an ApiResponse.
81+
$response = $thePayClient->realizeIrregularSubscriptionPayment('uid_subscriptionpayment', $params);
7782

7883
if ($response->wasSuccessful()) {
7984
echo 'Subscription payment was realized';
8085
}
8186
```
8287

83-
### Realizing usage based subscription payment type
88+
### Realizing a Usage-Based (Fixed Interval & Variable Amount) Subscription
8489

8590
```php
8691
/** @var \ThePay\ApiClient\TheClient $thePayClient */
8792

88-
// first parameter is uid of new (child) payment
89-
// second parameter is amount in cents (in parent payment currency)
90-
$params = new \ThePay\ApiClient\Model\RealizeUsageBasedSubscriptionPaymentParams('childpayment3', 18000);
93+
// First param: UID of child payment
94+
// Second param: amount in cents (in the parent payment currency)
95+
$params = new \ThePay\ApiClient\Model\RealizeUsageBasedSubscriptionPaymentParams('uid_childpayment3', 18000);
9196

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

96101

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

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

0 commit comments

Comments
 (0)