forked from opencart/opencart
/
pp_express.php
107 lines (84 loc) · 3.63 KB
/
pp_express.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
<?php
class ControllerExtensionRecurringPPExpress extends Controller {
public function index() {
$this->load->language('extension/recurring/pp_express');
if (isset($this->request->get['order_recurring_id'])) {
$order_recurring_id = $this->request->get['order_recurring_id'];
} else {
$order_recurring_id = 0;
}
$this->load->model('account/recurring');
$recurring_info = $this->model_account_recurring->getOrderRecurring($order_recurring_id);
if ($recurring_info) {
$data['continue'] = $this->url->link('account/recurring', 'language=' . $this->config->get('config_language'));
// If the profile is active, suspended or pending teh cancel option can be used.
if ($recurring_info['status'] == 1 || $recurring_info['status'] == 4 || $recurring_info['status'] == 6) {
$data['order_recurring_id'] = $order_recurring_id;
} else {
$data['order_recurring_id'] = '';
}
return $this->load->view('extension/recurring/pp_express', $data);
}
}
public function cancel() {
$json = array();
$this->load->language('extension/recurring/pp_express');
//cancel an active recurring
$this->load->model('account/recurring');
if (isset($this->request->get['order_recurring_id'])) {
$order_recurring_id = $this->request->get['order_recurring_id'];
} else {
$order_recurring_id = 0;
}
$recurring_info = $this->model_account_recurring->getOrderRecurring($order_recurring_id);
if ($recurring_info && $recurring_info['reference']) {
if ($this->config->get('payment_pp_express_test')) {
$api_url = 'https://api-3t.sandbox.paypal.com/nvp';
$api_username = $this->config->get('payment_pp_express_sandbox_username');
$api_password = $this->config->get('payment_pp_express_sandbox_password');
$api_signature = $this->config->get('payment_pp_express_sandbox_signature');
} else {
$api_url = 'https://api-3t.paypal.com/nvp';
$api_username = $this->config->get('payment_pp_express_username');
$api_password = $this->config->get('payment_pp_express_password');
$api_signature = $this->config->get('payment_pp_express_signature');
}
$request = array(
'USER' => $api_username,
'PWD' => $api_password,
'SIGNATURE' => $api_signature,
'VERSION' => '109.0',
'BUTTONSOURCE' => 'OpenCart_2.0_EC',
'METHOD' => 'SetExpressCheckout',
'METHOD' => 'ManageRecurringPaymentsProfileStatus',
'PROFILEID' => $recurring_info['reference'],
'ACTION' => 'Cancel'
);
$curl = curl_init($api_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
if (!$response) {
$this->log(sprintf($this->language->get('error_curl'), curl_errno($curl), curl_error($curl)));
}
curl_close($curl);
$response_info = array();
parse_str($response, $response_info);
if (isset($response_info['PROFILEID'])) {
$this->model_account_recurring->editOrderRecurringStatus($order_recurring_id, 3);
$this->model_account_recurring->addOrderRecurringTransaction($order_recurring_id, 5);
$json['success'] = $this->language->get('text_cancelled');
} else {
$json['error'] = sprintf($this->language->get('error_not_cancelled'), $response_info['L_LONGMESSAGE0']);
}
} else {
$json['error'] = $this->language->get('error_not_found');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}