将自定义变量添加到贝宝并行支付 IPN PHP

Adding custom variable to paypal parallel payments IPN PHP

您好,我正在尝试实施 PAYPAL PARALLEL API,并且我正在尝试将自定义变量传递给贝宝 IPN 这是我的 PHP 代码,它在没有自定义变量的情况下工作,我不知道在哪里添加这个自定义字段:

$apiUrl = "https://svcs.sandbox.paypal.com/AdaptivePayments/";
$paypalUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=";

$headers = array(
    "X-PAYPAL-SECURITY-USERID : ".$paypal_user_id,
    "X-PAYPAL-SECURITY-PASSWORD : ".$paypal_pass,
    "X-PAYPAL-SECURITY-SIGNATURE : ".$paypal_user_signature,
    "X-PAYPAL-APPLICATION-ID : ".$paypal_app_id,
    "X-PAYPAL-REQUEST-DATA-FORMAT : JSON",
    "X-PAYPAL-RESPONSE-DATA-FORMAT : JSON"
);

// curl wrapper for sending thhings to paypal
function paypalSend($data,$call){
    global $apiUrl;
    global $headers;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL , $apiUrl.$call);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    return json_decode(curl_exec($ch),true);
}

//create the pay request
$createPacket = array(
    "actionType"=>"PAY",
    "currencyCode"=>"USD",
    "receiverList"=> array(
        "receiver" => array(
            array(
                "amount" => $amount,
                "email" => $email
            )
        )
    ),
    "returnUrl" => "http://www.mywebsite.com/finish_withdraw.php",
    "cancelUrl" => "http://www.mywebsite.com/cancel_withdraw.php",

    "requestEnvelope"=> array(
        "errorLanguage"=>"en_US",    // Language used to display errors
        "detailLevel"=>"ReturnAll"
    )
);

$response = paypalSend($createPacket, "Pay");

$payKey = $response['payKey'];
$paymentExecStatus = $response['paymentExecStatus'];

$detailPacket = array(
    "requestEnvelope"=> array(
        "errorLanguage"=>"en_US",    // Language used to display errors
        "detailLevel"=>"ReturnAll"
    ),
    "payKey" => $payKey,
    "receiverOptions" => array(
        array(
            "receiver"=> array("email" => $email),
            "invoiceData" => array(
                "item" => array(
                    array(
                        "name" => "product 1",
                        "price" => $amount,
                        "identifier" => "p1"
                    )
                )
            )
        )
    )
);

$response = paypalSend($detailPacket, "SetPaymentOptions");

//Wrapper to get payent details
$packet = array(
    "requestEnvelope"=> array(
        "errorLanguage"=>"en_US",    // Language used to display errors
        "detailLevel"=>"ReturnAll"
    ),
    "payKey" => $payKey,
);

$dets = paypalSend($packet, "GetPaymentOptions");

header('location: '.$paypalUrl.$payKey);

除非 paypal 在过去 3 年修复了一些东西,否则我能做到这一点的唯一方法是发送带连字符的数据作为 item_number

"item_number1": "t-253-22768-",

此格式为 "type" - "product id" - "user id" - "discount code"

我相信我在以下网站上找到了您问题的答案:

https://enjoysmile.com/paypal-adaptive-payment-ipn-with-custom-variables/

只需在 IPN URL 上添加您想要的变量即可。 示例:(在"cancel URL"之后添加如下代码) "ipnNotificationUrl" => "http://www.example.com/paypal_ipn.php?custom1=1&custom2=2',

如果您检查 IPN 消息,您会在 "ipn_notification_url" 值上收到此值。

希望对您有所帮助。