تابع ووکامرسی wc_refund_payment بازپرداخت هزینه محصول با کمک درگاه آنلاین

تابع ووکامرسی wc_refund_payment – بازپرداخت هزینه محصول با کمک درگاه آنلاین
Syntax – سینتکس
(bool|WP_Error) wc_refund_payment( (WC_Order) $order, (number) $amount, (string) $reason = '' );
Parameters – پارامتر ها (3)
- 1- $order (WC_Order)
- 2- $amount (number)
- 3- $reason (string)
Usage – نحوه استفاده
if ( !function_exists( 'wc_refund_payment' ) ) {
require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-order-functions.php';
}
// The order.
$order = null;
// The amount.
$amount = null;
// The reason.
$reason = '';
// NOTICE! Understand what this does before running.
$result = wc_refund_payment($order, $amount, $reason);
Defined – محل تعریف
/includes/wc-order-functions.php
function wc_refund_payment( $order, $amount, $reason = '' ) {
try {
if ( ! is_a( $order, 'WC_Order' ) ) {
throw new Exception( __( 'Invalid order.', woocommerce ) );
}
$gateway_controller = WC_Payment_Gateways::instance();
$all_gateways = $gateway_controller->payment_gateways();
$payment_method = $order->get_payment_method();
$gateway = isset( $all_gateways[ $payment_method ] ) ? $all_gateways[ $payment_method ] : false;
if ( ! $gateway ) {
throw new Exception( __( 'The payment gateway for this order does not exist.', woocommerce ) );
}
if ( ! $gateway->supports( 'refunds' ) ) {
throw new Exception( __( 'The payment gateway for this order does not support automatic refunds.', woocommerce ) );
}
$result = $gateway->process_refund( $order->get_id(), $amount, $reason );
if ( ! $result ) {
throw new Exception( __( 'Anerroroccurred while attempting to create the refund using the payment gateway API.', woocommerce ) );
}
if ( is_wp_error( $result ) ) {
throw new Exception( $result->get_error_message() );
}
return true;
} catch ( Exception $e ) {
return new WP_Error( error, $e->getMessage() );
}
}
versions – نسخه ها
از نسخه : 3.0.0
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر