|
@@ 79-102 (lines=24) @@
|
| 76 |
|
* @param float $amount |
| 77 |
|
* @return object Either an object of name value pairs for a success, or a WP_ERROR object. |
| 78 |
|
*/ |
| 79 |
|
public static function do_capture( $order, $amount = null ) { |
| 80 |
|
$raw_response = wp_safe_remote_post( |
| 81 |
|
self::$sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp', |
| 82 |
|
array( |
| 83 |
|
'method' => 'POST', |
| 84 |
|
'body' => self::get_capture_request( $order, $amount ), |
| 85 |
|
'timeout' => 70, |
| 86 |
|
'user-agent' => 'WooCommerce/' . WC()->version, |
| 87 |
|
'httpversion' => '1.1', |
| 88 |
|
) |
| 89 |
|
); |
| 90 |
|
|
| 91 |
|
WC_Gateway_Paypal::log( 'DoCapture Response: ' . print_r( $raw_response, true ) ); |
| 92 |
|
|
| 93 |
|
if ( empty( $raw_response['body'] ) ) { |
| 94 |
|
return new WP_Error( 'paypal-api', 'Empty Response' ); |
| 95 |
|
} elseif ( is_wp_error( $raw_response ) ) { |
| 96 |
|
return $raw_response; |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
parse_str( $raw_response['body'], $response ); |
| 100 |
|
|
| 101 |
|
return (object) $response; |
| 102 |
|
} |
| 103 |
|
|
| 104 |
|
/** |
| 105 |
|
* Refund an order via PayPal. |
|
@@ 111-134 (lines=24) @@
|
| 108 |
|
* @param string $reason |
| 109 |
|
* @return object Either an object of name value pairs for a success, or a WP_ERROR object. |
| 110 |
|
*/ |
| 111 |
|
public static function refund_transaction( $order, $amount = null, $reason = '' ) { |
| 112 |
|
$raw_response = wp_safe_remote_post( |
| 113 |
|
self::$sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp', |
| 114 |
|
array( |
| 115 |
|
'method' => 'POST', |
| 116 |
|
'body' => self::get_refund_request( $order, $amount, $reason ), |
| 117 |
|
'timeout' => 70, |
| 118 |
|
'user-agent' => 'WooCommerce/' . WC()->version, |
| 119 |
|
'httpversion' => '1.1', |
| 120 |
|
) |
| 121 |
|
); |
| 122 |
|
|
| 123 |
|
WC_Gateway_Paypal::log( 'Refund Response: ' . print_r( $raw_response, true ) ); |
| 124 |
|
|
| 125 |
|
if ( empty( $raw_response['body'] ) ) { |
| 126 |
|
return new WP_Error( 'paypal-api', 'Empty Response' ); |
| 127 |
|
} elseif ( is_wp_error( $raw_response ) ) { |
| 128 |
|
return $raw_response; |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
parse_str( $raw_response['body'], $response ); |
| 132 |
|
|
| 133 |
|
return (object) $response; |
| 134 |
|
} |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
/** |