dongzinen1061 2015-03-13 18:12
浏览 103
已采纳

添加自定义变量到paypal并行支付IPN PHP

Hello i'm trying to implement the PAYPAL PARALLEL API, and i'm trying to pass a custom variable to paypal IPN this my PHP code, its working without the custom variable, and i don"t know where to add this custom field:

$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);
  • 写回答

2条回答 默认 最新

  • duanjiong1952 2015-03-14 01:21
    关注

    Unless paypal fixed something in the last 3 years, the ONLY way I could accomplish this was to send hyphenated data as the item_number

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

    This format was "type" - "product id" - "user id" - "discount code"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!