File "class-wc-gateway-paypal-api-handler.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-api-handler.php
File
size: 3.6 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
if (!defined('ABSPATH')) {
exit;
}
class WC_Gateway_Paypal_API_Handler
{
public static $api_username;
public static $api_password;
public static $api_signature;
public static $sandbox = false;
public static function get_capture_request($order, $amount = null)
{
$request = array('VERSION' => '84.0', 'SIGNATURE' => self::$api_signature, 'USER' => self::$api_username, 'PWD' => self::$api_password, 'METHOD' => 'DoCapture', 'AUTHORIZATIONID' => $order->get_transaction_id(), 'AMT' => number_format(is_null($amount) ? $order->get_total() : $amount, 2, '.', ''), 'CURRENCYCODE' => $order->get_currency(), 'COMPLETETYPE' => 'Complete');
return apply_filters('woocommerce_paypal_capture_request', $request, $order, $amount);
}
public static function get_refund_request($order, $amount = null, $reason = '')
{
$request = array('VERSION' => '84.0', 'SIGNATURE' => self::$api_signature, 'USER' => self::$api_username, 'PWD' => self::$api_password, 'METHOD' => 'RefundTransaction', 'TRANSACTIONID' => $order->get_transaction_id(), 'NOTE' => html_entity_decode(wc_trim_string($reason, 255), ENT_NOQUOTES, 'UTF-8'), 'REFUNDTYPE' => 'Full');
if (!is_null($amount)) {
$request['AMT'] = number_format($amount, 2, '.', '');
$request['CURRENCYCODE'] = $order->get_currency();
$request['REFUNDTYPE'] = 'Partial';
}
return apply_filters('woocommerce_paypal_refund_request', $request, $order, $amount, $reason);
}
public static function do_capture($order, $amount = null)
{
$raw_response = wp_safe_remote_post(self::$sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp', array('method' => 'POST', 'body' => self::get_capture_request($order, $amount), 'timeout' => 70, 'user-agent' => 'WooCommerce/' . WC()->version, 'httpversion' => '1.1'));
WC_Gateway_Paypal::log('DoCapture Response: ' . wc_print_r($raw_response, true));
if (is_wp_error($raw_response)) {
return $raw_response;
} elseif (empty($raw_response['body'])) {
return new WP_Error('paypal-api', 'Empty Response');
}
parse_str($raw_response['body'], $response);
return (object) $response;
}
public static function refund_transaction($order, $amount = null, $reason = '')
{
$raw_response = wp_safe_remote_post(self::$sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp', array('method' => 'POST', 'body' => self::get_refund_request($order, $amount, $reason), 'timeout' => 70, 'user-agent' => 'WooCommerce/' . WC()->version, 'httpversion' => '1.1'));
WC_Gateway_Paypal::log('Refund Response: ' . wc_print_r($raw_response, true));
if (is_wp_error($raw_response)) {
return $raw_response;
} elseif (empty($raw_response['body'])) {
return new WP_Error('paypal-api', 'Empty Response');
}
parse_str($raw_response['body'], $response);
return (object) $response;
}
}
class WC_Gateway_Paypal_Refund extends WC_Gateway_Paypal_API_Handler
{
public static function get_request($order, $amount = null, $reason = '')
{
return self::get_refund_request($order, $amount, $reason);
}
public static function refund_order($order, $amount = null, $reason = '', $sandbox = false)
{
if ($sandbox) {
self::$sandbox = $sandbox;
}
$result = self::refund_transaction($order, $amount, $reason);
if (is_wp_error($result)) {
return $result;
} else {
return (array) $result;
}
}
}