1 | <?php |
||
10 | abstract class Payment_Adaptive extends Payment { |
||
11 | |||
12 | const AP_ENDPOINT_START = 'https://svcs.'; |
||
13 | |||
14 | const AP_ENDPOINT_END = 'paypal.com/AdaptivePayments'; |
||
15 | |||
16 | const WEBAPPS_ENDPOINT_END = 'paypal.com/webapps/adaptivepayment/flow/pay'; |
||
17 | |||
18 | const ERROR_LANGUAGE = 'en_US'; |
||
19 | |||
20 | const DETAIL_LEVEL = 'ReturnAll'; |
||
21 | |||
22 | 1 | public static function webapps_url(array $params = array(), $mobile = FALSE) |
|
34 | |||
35 | /** |
||
36 | * API url for AdaptivePayments based on operation and environment |
||
37 | */ |
||
38 | 1 | public static function ap_api_url($operation = NULL) |
|
51 | |||
52 | 4 | public static function parse_response($response_string, $url, $request_data) |
|
53 | { |
||
54 | 4 | $response = Util::parse_str($response_string); |
|
55 | |||
56 | 4 | if (empty($response['responseEnvelope.ack']) |
|
57 | 4 | OR strpos($response['responseEnvelope.ack'], 'Success') === FALSE |
|
58 | 4 | OR (isset($response['paymentExecStatus']) AND ! in_array($response['paymentExecStatus'], array('CREATED', 'COMPLETED', 'INCOMPLETE', 'PROCESSING', 'PENDING')))) |
|
59 | { |
||
60 | 1 | if ( ! empty($response['error(0).message'])) |
|
61 | { |
||
62 | $error_message = $response['error(0).message']; |
||
63 | } |
||
64 | 1 | elseif ( ! empty($response['payErrorList']) |
|
65 | 1 | OR ( ! empty($response['paymentExecStatus']) |
|
66 | 1 | AND in_array($response['paymentExecStatus'], array( |
|
67 | 1 | 'ERROR', |
|
68 | 'REVERSALERROR' |
||
69 | ))) |
||
70 | ) |
||
71 | { |
||
72 | 1 | if (empty($response['payErrorList'])) |
|
73 | { |
||
74 | 1 | $error_message = 'Status was '.$response['paymentExecStatus']; |
|
75 | } |
||
76 | else |
||
77 | { |
||
78 | 1 | $error_message = print_r($response['payErrorList'], TRUE); |
|
79 | } |
||
80 | } |
||
81 | else |
||
82 | { |
||
83 | $error_message = 'Unknown error'; |
||
84 | } |
||
85 | |||
86 | 1 | throw new Request_Exception( |
|
87 | 1 | 'PayPal API request did not succeed for :url failed: :error:code.', |
|
88 | 1 | $url, |
|
89 | 1 | $request_data, |
|
90 | array( |
||
91 | 1 | ':url' => $url, |
|
92 | 1 | ':error' => $error_message, |
|
93 | 1 | ':code' => isset($response['error(0).errorId']) |
|
94 | ? ' ('.$response['error(0).errorId'].')' |
||
95 | 1 | : '', |
|
96 | ), |
||
97 | 1 | $response |
|
98 | ); |
||
99 | } |
||
100 | |||
101 | 3 | return $response; |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * NVP fields required for the Pay API operation |
||
106 | */ |
||
107 | 1 | public function common_fields() |
|
114 | |||
115 | protected function _request($method, array $request_data = array()) |
||
132 | } |
||
133 |