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条)

报告相同问题?

悬赏问题

  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 YOLOv8obb获取边框坐标时报错AttributeError: 'NoneType' object has no attribute 'xywhr'