-
Notifications
You must be signed in to change notification settings - Fork 4
/
example.paymentRequest.installment.directDebit.php
executable file
·212 lines (190 loc) · 7.41 KB
/
example.paymentRequest.installment.directDebit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
require __DIR__ . '/vendor/autoload.php';
require_once "ratepay_credentials.php";
/******************************************************
* The PaymentRequest requests authorization of order *
******************************************************/
$mbHead = new RatePAY\ModelBuilder();
$mbHead->setArray([
'SystemId' => "Example",
'Credential' => [
'ProfileId' => PROFILE_ID,
'Securitycode' => SECURITYCODE
]
]);
$rb = new RatePAY\RequestBuilder(true);
$paymentInit = $rb->callPaymentInit($mbHead);
if (!$paymentInit->isSuccessful()) die("PaymentInit not successful");
// Extending head model with required customer device information
$mbHead->setTransactionId($paymentInit->getTransactionId());
$mbHead->setCustomerDevice(
$mbHead->CustomerDevice()->setDeviceToken("1234567890")
);
// External commits additional information about customer and order. Is optional.
$mbHead->setArray([
'External' => [
'MerchantConsumerId' => "1234567", // Customer Id
'OrderId' => "xyzabc"
//'MerchantConsumerClassification' => "X"
//'ShopLanguage' => "DEU"
//'ReferenceId' => "xyzabc"
]
]);
// The PaymentRequest requires a content model.
// Building content model
$mbContent = new RatePAY\ModelBuilder('Content');
$contentArr = [
'Customer' => [
'Gender' => "f",
//'Salutation' => "Mrs.",
//'Title' => "Dr.",
'FirstName' => "Alice",
//'MiddleName' => "J.",
'LastName' => "Nobodyknows",
//'NameSuffix' => "Sen.",
'DateOfBirth' => "1975-12-17",
//'Nationality' => "DE",
//'Language' => "DE",
'IpAddress' => "127.0.0.1",
'Addresses' => [
[
'Address' => [
'Type' => "billing",
'Street' => "Hive Street 12",
//'StreetAdditional' => "SubLevel 27",
//'StreetNumber' => "12",
'ZipCode' => "12345",
'City' => "Raccoon City",
'CountryCode' => "de",
]
], [
'Address' => [
'Type' => "delivery",
//'Salutation' => "Mrs.",
'FirstName' => "Alice",
'LastName' => "Nobodyknows",
//'Company' => "Umbrella Corp.",
'Street' => "Hive Street 12",
//'StreetAdditional' => "SubLevel 27",
//'StreetNumber' => "12",
'ZipCode' => "12345",
'City' => "Raccoon City",
'CountryCode' => "de",
]
]
],
'Contacts' => [
'Email' => "alice@umbrella.tld",
//'Mobile' => [
//'AreaCode' => "0172",
//'DirectDial' => "0172 3456789"
//],
'Phone' => [
//'AreaCode' => "012",
'DirectDial' => "012 3456789"
],
//'Fax' => [
//'AreaCode' => "012",
//'DirectDial' => "012 3456789"
//],
],
'BankAccount' => [ // In case of payment method 'elv'
'Owner' => "Alice Nobodyknows",
'Iban' => "AT123456789012345678",
//'BankName' => "Umbrella Finance",
//'BankAccountNumber' => "1234567890",
//'BankCode' => "12345678",
],
// 'CompanyName' => "Umbrella Corp.",
// 'CompanyType' => "AG",
// 'VatId' => "DE123456789",
// 'CompanyId' => "HRB 123456X",
// 'RegistryLocation' => "Raccoon City",
// 'Homepage' => "http://www.umbrellacorporation.tld",
],
'ShoppingBasket' => [
'Items' => [
[
'Item' => [
'Description' => "Test product 1",
'ArticleNumber' => "ArtNo1",
//'UniqueArticleNumber' => "ArtNo1-variation123",
'Quantity' => 1,
'UnitPriceGross' => 300,
'TaxRate' => 19,
//'Category' => "Additional information about the product"
//'DescriptionAddition' => "Additional information about the product"
]
], [
'Item' => [
'Description' => "Test product 2",
'ArticleNumber' => "ArtNo",
'Quantity' => 2,
'UnitPriceGross' => 100,
'TaxRate' => 19,
'Discount' => 10
]
]
],
'Shipping' => [
'Description' => "Shipping costs",
'UnitPriceGross' => 4.95,
'TaxRate' => 19,
//'DescriptionAddition' => "Additional information about the shipping"
],
'Discount' => [
'Description' => "Discount 20 EUR",
'UnitPriceGross' => 20,
'TaxRate' => 19,
//'DescriptionAddition' => "Additional information about the discount"
]
],
'Payment' => [
'Method' => "installment",
'Amount' => 483.25,
'InstallmentDetails' => [
'InstallmentNumber' => 6,
'InstallmentAmount' => 80.55,
'LastInstallmentAmount' => 80.5,
'InterestRate' => 9.8,
'PaymentFirstday' => 2,
],
'DebitPayType' => "DIRECT-DEBIT"
]
];
$mbContent->setArray($contentArr);
$rb = new RatePAY\RequestBuilder(true); // Sandbox mode = true
$paymentRequest = $rb->callPaymentRequest($mbHead, $mbContent);
if (!$paymentRequest->isSuccessful()) die("PaymentRequest not successful");
// The PaymentRequest response object provides following methods:
// getTransactionId(); // Returns transaction id (unique transaction identifier) {string}
// isRetryAdmitted(); // Returns whether retry is admitted {boolean}
// getCustomerMessage(); // Returns customer message {string}
var_dump($paymentRequest->getTransactionId());
// If the order gets rejected by RatePAY because of invalid inputs (like invalid zip code or iban), a retry of order is allowed.
var_dump($paymentRequest->isRetryAdmitted());
// If retry of order is allowed, the there will be a customer message with further information.
var_dump($paymentRequest->getCustomerMessage());
// Example of rejection with allowed retry and customer message:
$mbHead = new RatePAY\ModelBuilder();
$mbHead->setArray([
'SystemId' => "Example",
'Credential' => [
'ProfileId' => PROFILE_ID,
'Securitycode' => SECURITYCODE
]
]);
$paymentInit = $rb->callPaymentInit($mbHead);
$mbHead->setTransactionId($paymentInit->getTransactionId());
$mbHead->setCustomerDevice(
$mbHead->CustomerDevice()->setDeviceToken("1234567890")
);
$contentArr['Customer']['Addresses'][0]['Address']['ZipCode'] = "1234";
$mbContent->setArray($contentArr);
$rb = new RatePAY\RequestBuilder(true);
$paymentRequest = $rb->callPaymentRequest($mbHead, $mbContent);
var_dump($paymentRequest->isRetryAdmitted());
var_dump($paymentRequest->getCustomerMessage());
/*********************************************************************************************************************************
* The library throws decidedly exceptions. It's recommended to surround model building and request calls with try-catch-blocks. *
*********************************************************************************************************************************/