WooCommerce是否有内置捕获方法?

时间:2019-07-05 13:10:58

标签: woocommerce payment-gateway

我可以看到一个函数定义如下。但是不确定woocommerce是否为自动捕获提供此选项?

他们提供了process_payment($ order_id)的方法。关于如何捕获它的任何建议?

public function process_capture( $order_id ) {
        $order = wc_get_order( $order_id );

        // Return if another payment method was used
        $payment_method = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->payment_method : $order->get_payment_method();
        if ( $payment_method != $this->id ) {
            return;
        }

        // Attempt to process the capture
        $tran_meta = get_post_meta( $order_id, '_payeezy_transaction', true);
        $orig_tran_type = $tran_meta['transaction_type'];
        $amount = $order->get_total();

        if ( 'authorize' == $orig_tran_type && 'yes' == $this->auto_capture ) {
            try {
                $payeezy = new WC_Payeezy_API();
                $response = $payeezy->capture( $this, $order, $amount );

                if ( is_wp_error( $response ) ) {
                    throw new Exception( $response->get_error_message() );
                }

                if ( isset( $response->transaction_status ) && 'approved' == $response->transaction_status ) {
                    $captured_amount = number_format( $response->amount / 100, '2', '.', '' );
                    $order->add_order_note( sprintf( __( 'Payeezy auto capture completed for %s. Capture ID: %s', 'woocommerce-payeezy' ), $captured_amount, $response->transaction_id ) );
                    $tran_meta = array(
                        'transaction_id' => $response->transaction_id,
                        'transaction_tag' => $response->transaction_tag,
                        'transaction_type' => 'capture',
                    );
                    update_post_meta( $order_id, '_payeezy_transaction', $tran_meta );
                    return true;
                } else {
                    throw new Exception( __( 'Payeezy auto capture failed. Log into your gateway to manually process the capture.', 'woocommerce-payeezy' ) );
                }
            } catch ( Exception $e ) {
                $order->add_order_note( $e->getMessage() );
                return true;
            }
        }
    }

0 个答案:

没有答案