如何从PayPal获取付款详细信息,如PaymentID,PaymentFirstName / LastName和其他详细信息?
答案 0 :(得分:1)
代码PayPal Standard集成使用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'
- PayPal付款状态