2017-10-24 16 views

答えて

0

コードPayPal標準インテグレーションでは、有効なIPN応答を処理するためにアクションvalid-paypal-standard-ipn-requestが使用されます。同じアクションを使って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支払いステータス

関連する問題