【问题标题】:Get Paypal Payment Details on WooCommerce在 WooCommerce 上获取 Paypal 付款详细信息
【发布时间】:2018-04-05 02:44:44
【问题描述】:

如何从 Paypal 获取付款详细信息,例如 PaymentID、PaymentFirstName/LastName 和其他详细信息?

【问题讨论】:

    标签: php paypal woocommerce


    【解决方案1】:

    代码 PayPal 标准集成使用 valid-paypal-standard-ipn-request 操作来处理有效的 IPN 响应。您可以使用相同的操作连接到 IPN 并获取/存储您想要的任何信息。 要保存其他信息:

    // Hook before the code has processed the order
    add_action( 'valid-paypal-standard-ipn-request', 'prefix_process_valid_ipn_response', 9 );
    function prefix_process_valid_ipn_response( $posted ) {
        if ( ! empty( $posted['custom'] ) && ( $order = prefix_get_paypal_order( $posted['custom'] ) ) ) {
    
            // Lowercase returned variables.
            $posted['payment_status'] = strtolower( $posted['payment_status'] );
    
            // Any status can be checked here 
            if ( 'completed' == $posted['payment_status'] ) {
                // Save additional information you want
            }
        }
    }
    
    /**
     * From the Abstract "WC_Gateway_Paypal_Response" class
     *
     * @param $raw_custom
     *
     * @return bool|WC_Order|WC_Refund
     */
    function prefix_get_paypal_order( $raw_custom ) {
        // We have the data in the correct format, so get the order.
        if ( ( $custom = json_decode( $raw_custom ) ) && is_object( $custom ) ) {
            $order_id  = $custom->order_id;
            $order_key = $custom->order_key;
    
            // Nothing was found.
        } else {
            return false;
        }
    
        if ( ! $order = wc_get_order( $order_id ) ) {
            // We have an invalid $order_id, probably because invoice_prefix has changed.
            $order_id = wc_get_order_id_by_order_key( $order_key );
            $order    = wc_get_order( $order_id );
        }
    
        if ( ! $order || $order->get_order_key() !== $order_key ) {
            return false;
        }
    
        return $order;
    }
    

    您可以在此处找到 PayPal 变量:https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNIntro/#id08CKFJ00JYK

    WC 核心也已经为命令保存了很多 IPN 数据。所有数据都保存到订单元数据中,因此您可以使用get_post_meta$order->get_meta('meta_key') 访问它。

    meta_key列出:

    'Payer PayPal address' - 付款人地址

    'Payer first name' - 付款人名字

    'Payer last name' - 付款人姓氏

    'Payment type' - 付款方式

    '_paypal_status' - 贝宝付款状态

    【讨论】:

      猜你喜欢
      • 2020-10-16
      • 2023-04-06
      • 2014-02-23
      • 2015-07-22
      • 2015-04-24
      • 2018-08-30
      • 2021-06-06
      • 2011-12-01
      • 2016-01-03
      相关资源
      最近更新 更多