[英]Get Paypal Payment Details on WooCommerce
如何从 Paypal 获取付款详细信息,例如 PaymentID、PaymentFirstName/LastName 和其他详细信息?
The code PayPal Standard integration uses valid-paypal-standard-ipn-request
action to process the valid IPN response.代码 PayPal Standard 集成使用
valid-paypal-standard-ipn-request
操作来处理有效的 IPN 响应。 You can use the same action to hook into the IPN and get/store any information you want.您可以使用相同的操作连接到 IPN 并获取/存储您想要的任何信息。 To save additional information:
要保存附加信息:
// 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;
}
You can find the PayPal variables here: https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNIntro/#id08CKFJ00JYK您可以在此处找到 PayPal 变量: https : //developer.paypal.com/docs/classic/ipn/integration-guide/IPNIntro/#id08CKFJ00JYK
The WC core also saves to the order a lot of the IPN data already. WC 核心也已将大量 IPN 数据保存到命令中。 All data is saved to the order meta, so you can access it using
get_post_meta
or $order->get_meta('meta_key')
.所有数据都保存到订单元数据中,因此您可以使用
get_post_meta
或$order->get_meta('meta_key')
访问它。
List by meta_key
:按
meta_key
列出:
'Payer PayPal address'
- The payer address 'Payer PayPal address'
- 付款人地址
'Payer first name'
- Payer first name 'Payer first name'
- 付款人名字
'Payer last name'
- Payer last name 'Payer last name'
- 付款人姓氏
'Payment type'
- Payment Type 'Payment type'
- 付款类型
'_paypal_status'
- PayPal payment status '_paypal_status'
- PayPal 付款状态
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.