-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpayByLink.php
150 lines (134 loc) · 3.39 KB
/
payByLink.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
<?php
/**
* Include composer class autoloader
*/
require_once dirname(__FILE__) . '/../vendor/autoload.php';
use PayU\Alu\Billing;
use PayU\Alu\Client;
use PayU\Alu\Delivery;
use PayU\Alu\MerchantConfig;
use PayU\Alu\Order;
use PayU\Alu\Product;
use PayU\Alu\Request;
use PayU\Alu\User;
use PayU\Alu\Exceptions\ConnectionException;
use PayU\Alu\Exceptions\ClientException;
use PayU\PaymentsApi\AluV3\AluV3;
/**
* Create configuration with params:
*
* Merchant Code - Your PayU Merchant Code
* Secret Key - Your PayU Secret Key
* Platform - RO | RU | UA | TR | HU
*/
$cfg = new MerchantConfig('MERCHANT_CODE', 'SECRET_KEY', 'TR');
/**
* Create user with params:
*
* User IP - User's IP address
* User Time - Time of user computer - optional
*
*/
$user = new User('127.0.0.1');
/**
* Create new order
*/
$order = new Order();
/**
* Setup the order params
*
* Full params available in the documentation
*/
$order->withBackRef('http://path/to/your/returnUrlScript')
->withOrderRef('MerchantOrderRef')
->withCurrency('TRY')
->withOrderDate(gmdate('Y-m-d H:i:s'))
->withOrderTimeout(1000)
->withPayMethod('BKM');
/**
* Create new product
*/
$product = new Product();
/**
* Setup the product params
*
* Full params available in the documentation
*/
$product->withCode('PCODE01')
->withName('PNAME01')
->withPrice(100.0)
->withVAT(24.0)
->withQuantity(1);
/**
* Add the product to the order
*/
$order->addProduct($product);
/**
* Create new billing address
*/
$billing = new Billing();
/**
* Setup the billing address params
*
* Full params available in the documentation
*/
$billing->withAddressLine1('Address1')
->withAddressLine2('Address2')
->withCity('City')
->withCountryCode('RO')
->withEmail('[email protected]')
->withFirstName('FirstName')
->withLastName('LastName')
->withPhoneNumber('40123456789')
->withIdentityCardNumber('111222');
/**
* Create new delivery address
*
* If you want to have the same delivery as billing, skip these two steps
* and pass the Billing $billing object to the request twice
*/
$delivery = new Delivery();
/**
* Setup the delivery address params
*
* Full params available in the documentation
*/
$delivery->withAddressLine1('Address1')
->withAddressLine2('Address2')
->withCity('City')
->withCountryCode('RO')
->withEmail('[email protected]')
->withFirstName('FirstName')
->withLastName('LastName')
->withPhoneNumber('40123456789');
/**
* Create new Request with params:
*
* Config object
* Order object
* Billing object
* Delivery (or Billing object again, if you want to have the delivery address the same as the billing address)
* User object
* Api version - by default is used 'v3' for ALU v3
*/
$request = new Request($cfg, $order, $billing, $delivery, $user, AluV3::API_VERSION_V3);
/**
* Create new API Client, passing the Config object as parameter
*/
$client = new Client($cfg);
/**
* Will throw different Exceptions on errors
*/
try {
/**
* Sends the Request to ALU and returns a Response
*
* See documentation for Response params
*/
$response = $client->pay($request);
echo $response->getReturnMessage() . ' ' . $response->getRefno() . ' ' . $response->getUrlRedirect();
} catch (ConnectionException $exception) {
echo $exception->getMessage();
} catch (ClientException $exception) {
echo $exception->getErrorMessage();
}