forked from ratepay/php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.paymentQuery.php
executable file
·104 lines (91 loc) · 3.28 KB
/
example.paymentQuery.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
<?php
require __DIR__ . '/vendor/autoload.php';
require_once "ratepay_credentials.php";
/********************************************************************************************
* The PaymentQuery pre-requests authorization of order and returns allowed payment methods *
********************************************************************************************/
$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")
);
// The PaymentQuery requires a content model.
// Building content model
$mbContent = new RatePAY\ModelBuilder('Content');
$mbContent->setArray([
'Customer' => [
'Gender' => "f",
'FirstName' => "Alice",
'LastName' => "Nobodyknows",
'DateOfBirth' => "1975-12-17",
'IpAddress' => "127.0.0.1",
'Addresses' => [
[
'Address' => [
'Type' => "billing",
'Street' => "Hive Street 12",
'ZipCode' => "12345",
'City' => "Raccoon City",
'CountryCode' => "de",
]
]
],
'Contacts' => [
'Email' => "alice@umbrella.tld",
'Phone' => [
'DirectDial' => "012 3456789"
],
],
],
'ShoppingBasket' => [
'Items' => [
[
'Item' => [
'Description' => "Test product 1",
'ArticleNumber' => "ArtNo1",
'Quantity' => 1,
'UnitPriceGross' => 300,
'TaxRate' => 19,
]
], [
'Item' => [
'Description' => "Test product 2",
'ArticleNumber' => "ArtNo2",
'Quantity' => 2,
'UnitPriceGross' => 100,
'TaxRate' => 19,
'Discount' => 10
]
]
],
'Shipping' => [
'Description' => "Shipping costs",
'UnitPriceGross' => 4.95,
'TaxRate' => 19,
],
'Discount' => [
'Description' => "Discount 20 EUR",
'UnitPriceGross' => 20,
'TaxRate' => 19,
]
]
]);
$rb = new RatePAY\RequestBuilder(true); // Sandbox mode = true
// PaymentQuery has to be specified by subtype (always 'full')
$paymentQuery = $rb->callPaymentQuery($mbHead, $mbContent)->subtype('full');
if (!$paymentQuery->isSuccessful()) die("PaymentQuery not successful");
// The PaymentQuery response object provides following methods:
// getTransactionId(); // Returns transaction id (unique transaction identifier) {string}
// getAdmittedPaymentMethods(); // Returns which payment methods are admitted for order (array)
var_dump($paymentQuery->getAdmittedPaymentMethods());