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.0.9 6.2.0-rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / gateways / paypal / includes / class-wc-gateway-paypal-api-handler.php
woocommerce / includes / gateways / paypal / includes Last commit date
class-wc-gateway-paypal-api-handler.php 5 years ago class-wc-gateway-paypal-constants.php 6 months ago class-wc-gateway-paypal-helper.php 6 months ago class-wc-gateway-paypal-ipn-handler.php 6 months ago class-wc-gateway-paypal-notices.php 6 months ago class-wc-gateway-paypal-pdt-handler.php 6 months ago class-wc-gateway-paypal-request.php 6 months ago class-wc-gateway-paypal-response.php 1 year ago class-wc-gateway-paypal-transact-account-manager.php 6 months ago class-wc-gateway-paypal-webhook-handler.php 6 months ago settings-paypal.php 9 months ago
class-wc-gateway-paypal-api-handler.php
203 lines
1 <?php
2 /**
3 * Class WC_Gateway_Paypal_API_Handler file.
4 *
5 * @package WooCommerce\Gateways
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Handles Refunds and other API requests such as capture.
14 *
15 * @since 3.0.0
16 */
17 class WC_Gateway_Paypal_API_Handler {
18
19 /**
20 * API Username
21 *
22 * @var string
23 */
24 public static $api_username;
25
26 /**
27 * API Password
28 *
29 * @var string
30 */
31 public static $api_password;
32
33 /**
34 * API Signature
35 *
36 * @var string
37 */
38 public static $api_signature;
39
40 /**
41 * Sandbox
42 *
43 * @var bool
44 */
45 public static $sandbox = false;
46
47 /**
48 * Get capture request args.
49 * See https://developer.paypal.com/docs/classic/api/merchant/DoCapture_API_Operation_NVP/.
50 *
51 * @param WC_Order $order Order object.
52 * @param float $amount Amount.
53 * @return array
54 */
55 public static function get_capture_request( $order, $amount = null ) {
56 $request = array(
57 'VERSION' => '84.0',
58 'SIGNATURE' => self::$api_signature,
59 'USER' => self::$api_username,
60 'PWD' => self::$api_password,
61 'METHOD' => 'DoCapture',
62 'AUTHORIZATIONID' => $order->get_transaction_id(),
63 'AMT' => number_format( is_null( $amount ) ? $order->get_total() : $amount, 2, '.', '' ),
64 'CURRENCYCODE' => $order->get_currency(),
65 'COMPLETETYPE' => 'Complete',
66 );
67 return apply_filters( 'woocommerce_paypal_capture_request', $request, $order, $amount );
68 }
69
70 /**
71 * Get refund request args.
72 *
73 * @param WC_Order $order Order object.
74 * @param float $amount Refund amount.
75 * @param string $reason Refund reason.
76 * @return array
77 */
78 public static function get_refund_request( $order, $amount = null, $reason = '' ) {
79 $request = array(
80 'VERSION' => '84.0',
81 'SIGNATURE' => self::$api_signature,
82 'USER' => self::$api_username,
83 'PWD' => self::$api_password,
84 'METHOD' => 'RefundTransaction',
85 'TRANSACTIONID' => $order->get_transaction_id(),
86 'NOTE' => html_entity_decode( wc_trim_string( $reason, 255 ), ENT_NOQUOTES, 'UTF-8' ),
87 'REFUNDTYPE' => 'Full',
88 );
89 if ( ! is_null( $amount ) ) {
90 $request['AMT'] = number_format( $amount, 2, '.', '' );
91 $request['CURRENCYCODE'] = $order->get_currency();
92 $request['REFUNDTYPE'] = 'Partial';
93 }
94 return apply_filters( 'woocommerce_paypal_refund_request', $request, $order, $amount, $reason );
95 }
96
97 /**
98 * Capture an authorization.
99 *
100 * @param WC_Order $order Order object.
101 * @param float $amount Amount.
102 * @return object Either an object of name value pairs for a success, or a WP_ERROR object.
103 */
104 public static function do_capture( $order, $amount = null ) {
105 $raw_response = wp_safe_remote_post(
106 self::$sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp',
107 array(
108 'method' => 'POST',
109 'body' => self::get_capture_request( $order, $amount ),
110 'timeout' => 70,
111 'user-agent' => 'WooCommerce/' . WC()->version,
112 'httpversion' => '1.1',
113 )
114 );
115
116 WC_Gateway_Paypal::log( 'DoCapture Response: ' . wc_print_r( $raw_response, true ) );
117
118 if ( is_wp_error( $raw_response ) ) {
119 return $raw_response;
120 } elseif ( empty( $raw_response['body'] ) ) {
121 return new WP_Error( 'paypal-api', 'Empty Response' );
122 }
123
124 parse_str( $raw_response['body'], $response );
125
126 return (object) $response;
127 }
128
129 /**
130 * Refund an order via PayPal.
131 *
132 * @param WC_Order $order Order object.
133 * @param float $amount Refund amount.
134 * @param string $reason Refund reason.
135 * @return object Either an object of name value pairs for a success, or a WP_ERROR object.
136 */
137 public static function refund_transaction( $order, $amount = null, $reason = '' ) {
138 $raw_response = wp_safe_remote_post(
139 self::$sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp',
140 array(
141 'method' => 'POST',
142 'body' => self::get_refund_request( $order, $amount, $reason ),
143 'timeout' => 70,
144 'user-agent' => 'WooCommerce/' . WC()->version,
145 'httpversion' => '1.1',
146 )
147 );
148
149 WC_Gateway_Paypal::log( 'Refund Response: ' . wc_print_r( $raw_response, true ) );
150
151 if ( is_wp_error( $raw_response ) ) {
152 return $raw_response;
153 } elseif ( empty( $raw_response['body'] ) ) {
154 return new WP_Error( 'paypal-api', 'Empty Response' );
155 }
156
157 parse_str( $raw_response['body'], $response );
158
159 return (object) $response;
160 }
161 }
162
163 /**
164 * Here for backwards compatibility.
165 *
166 * @since 3.0.0
167 */
168 class WC_Gateway_Paypal_Refund extends WC_Gateway_Paypal_API_Handler {
169 /**
170 * Get refund request args. Proxy to WC_Gateway_Paypal_API_Handler::get_refund_request().
171 *
172 * @param WC_Order $order Order object.
173 * @param float $amount Refund amount.
174 * @param string $reason Refund reason.
175 *
176 * @return array
177 */
178 public static function get_request( $order, $amount = null, $reason = '' ) {
179 return self::get_refund_request( $order, $amount, $reason );
180 }
181
182 /**
183 * Process an order refund.
184 *
185 * @param WC_Order $order Order object.
186 * @param float $amount Refund amount.
187 * @param string $reason Refund reason.
188 * @param bool $sandbox Whether to use sandbox mode or not.
189 * @return object Either an object of name value pairs for a success, or a WP_ERROR object.
190 */
191 public static function refund_order( $order, $amount = null, $reason = '', $sandbox = false ) {
192 if ( $sandbox ) {
193 self::$sandbox = $sandbox;
194 }
195 $result = self::refund_transaction( $order, $amount, $reason );
196 if ( is_wp_error( $result ) ) {
197 return $result;
198 } else {
199 return (array) $result;
200 }
201 }
202 }
203