|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OpenBuildings\PayPal; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @author Haralan Dobrev <[email protected]> |
|
7
|
|
|
* @copyright 2013 OpenBuildings, Inc. |
|
8
|
|
|
* @license http://spdx.org/licenses/BSD-3-Clause |
|
9
|
|
|
*/ |
|
10
|
|
|
class Payment_ExpressCheckout extends Payment { |
|
11
|
|
|
|
|
12
|
|
|
const API_VERSION = '98.0'; |
|
13
|
|
|
|
|
14
|
2 |
|
public function get_express_checkout_details(array $params) |
|
15
|
|
|
{ |
|
16
|
2 |
|
if ( ! isset($params['TOKEN'])) |
|
17
|
1 |
|
throw new Exception( |
|
18
|
1 |
|
'You must provide a TOKEN parameter for method "'.__METHOD__.'"' |
|
19
|
|
|
); |
|
20
|
|
|
|
|
21
|
1 |
|
return $this->_request('GetExpressCheckoutDetails', $params); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Make an SetExpressCheckout call. |
|
26
|
|
|
*/ |
|
27
|
1 |
|
public function set_express_checkout(array $params = array()) |
|
28
|
|
|
{ |
|
29
|
1 |
|
return $this->_request('SetExpressCheckout', $this->_set_params($params)); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
public function do_express_checkout_payment($token, $payer_id) |
|
33
|
|
|
{ |
|
34
|
1 |
|
$order = $this->order(); |
|
35
|
|
|
|
|
36
|
1 |
|
return $this->_request('DoExpressCheckoutPayment', array( |
|
37
|
1 |
|
'TOKEN' => $token, |
|
38
|
1 |
|
'PAYERID' => $payer_id, |
|
39
|
|
|
|
|
40
|
|
|
// Total amount of the order |
|
41
|
1 |
|
'PAYMENTREQUEST_0_AMT' => number_format($order['total_price'], 2, '.', ''), |
|
42
|
|
|
|
|
43
|
|
|
// Price of the items being sold |
|
44
|
1 |
|
'PAYMENTREQUEST_0_ITEMAMT' => number_format($order['items_price'], 2, '.', ''), |
|
45
|
|
|
|
|
46
|
|
|
// Shipping costs for the whole transaction |
|
47
|
1 |
|
'PAYMENTREQUEST_0_SHIPPINGAMT' => number_format($order['shipping_price'], 2, '.', ''), |
|
48
|
|
|
|
|
49
|
1 |
|
'PAYMENTREQUEST_0_CURRENCYCODE' => $this->config('currency'), |
|
50
|
|
|
|
|
51
|
1 |
|
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale' |
|
52
|
|
|
)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
1 |
|
protected function _set_params(array $params = array()) |
|
56
|
|
|
{ |
|
57
|
1 |
|
$order = $this->order(); |
|
58
|
|
|
|
|
59
|
|
|
$defaultParams = array( |
|
60
|
|
|
// Total amount for the transaction |
|
61
|
1 |
|
'PAYMENTREQUEST_0_AMT' => number_format($order['total_price'], 2, '.', ''), |
|
62
|
|
|
|
|
63
|
|
|
// Price of the items being sold |
|
64
|
1 |
|
'PAYMENTREQUEST_0_ITEMAMT' => number_format($order['items_price'], 2, '.', ''), |
|
65
|
|
|
|
|
66
|
|
|
// Shipping costs for the whole transaction |
|
67
|
1 |
|
'PAYMENTREQUEST_0_SHIPPINGAMT' => number_format($order['shipping_price'], 2, '.', ''), |
|
68
|
|
|
|
|
69
|
1 |
|
'PAYMENTREQUEST_0_CURRENCYCODE' => $this->config('currency'), |
|
70
|
|
|
|
|
71
|
1 |
|
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
72
|
|
|
|
|
73
|
1 |
|
'RETURNURL' => $this->return_url(), |
|
74
|
|
|
|
|
75
|
1 |
|
'CANCELURL' => $this->cancel_url(), |
|
76
|
|
|
|
|
77
|
1 |
|
'useraction' => 'commit', |
|
78
|
|
|
|
|
79
|
|
|
// PayPal won't display shipping fields to the customer |
|
80
|
|
|
// For digital goods this field is required and it must be set to 1. |
|
81
|
1 |
|
'NOSHIPPING' => 1, |
|
82
|
|
|
|
|
83
|
1 |
|
'ADDROVERRIDE' => 0, |
|
84
|
|
|
); |
|
85
|
1 |
|
$params = array_merge($defaultParams, $params); |
|
86
|
|
|
|
|
87
|
1 |
|
if ($this->notify_url()) |
|
88
|
|
|
{ |
|
89
|
1 |
|
$params['PAYMENTREQUEST_0_NOTIFYURL'] = $this->notify_url(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
1 |
|
return $params; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
1 |
|
protected function _request($method, array $params = array()) |
|
96
|
|
|
{ |
|
97
|
1 |
|
return $this->request(static::merchant_endpoint_url(), array( |
|
98
|
1 |
|
'METHOD' => $method, |
|
99
|
|
|
'VERSION' => Payment_ExpressCheckout::API_VERSION, |
|
100
|
1 |
|
'USER' => $this->config('username'), |
|
101
|
1 |
|
'PWD' => $this->config('password'), |
|
102
|
1 |
|
'SIGNATURE' => $this->config('signature'), |
|
103
|
1 |
|
) + $params); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|