我正在使用PayPal自适应支付API,所有事情都可以使用,直到上个月。
问题是ipnNotificationUrl没有向代码中提供的URL i发送任何通知。
以下是PayPal自适应付款的代码,
<?php
class Paypal{
private $api_user;
private $api_pass;
private $api_sig;
private $app_id;
private $apiUrl = 'https://svcs.sandbox.paypal.com/AdaptivePayments/';
private $paypalUrl="https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=";
private $headers;
public function setDetails($api_u, $api_p, $api_s, $api_id){
$this->api_user = $api_u;
$this->api_pass = $api_p;
$this->api_sig = $api_s;
$this->app_id = $api_id;
$this->headers = array(
"X-PAYPAL-SECURITY-USERID: ".$this->api_user,
"X-PAYPAL-SECURITY-PASSWORD: ".$this->api_pass,
"X-PAYPAL-SECURITY-SIGNATURE: ".$this->api_sig,
"X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
"X-PAYPAL-APPLICATION-ID: ".$this->app_id,
);
}
public function getPaymentOptions($paykey){
$pack = array(
"requestEnvelope" => array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll",
),
"payKey" => $paykey
);
return $this->_paypalSend($pack, "GetPaymentOptions");
}
public function setPaymentOptions(){
}
public function _paypalSend($data,$call){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->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, $this->headers);
$response = json_decode(curl_exec($ch),true);
return $response;
}
public function splitPay($currency, $r1_email, $r2_email, $r1_amount, $r2_amount, $returnUrl, $cancelUrl, $product_name, $indentifier){
$createPacket = array(
"actionType" =>"PAY",
"currencyCode" => $currency,
"receiverList" => array("receiver" =>
array(
array(
"amount"=> $r1_amount,
"email"=> $r1_email
),
array(
"amount"=> $r2_amount,
"email"=> $r2_email
)
)
),
"returnUrl" => $returnUrl,
"cancelUrl" => $cancelUrl,
"ipnNotificationUrl" => URL::to('/adaptive_payments'),
"requestEnvelope" => array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll",
),
);
$response = $this->_paypalSend($createPacket,"Pay");
$paykey = $response['payKey'];
$detailsPack = array(
"requestEnvelope" => array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll",
),
"payKey" => $paykey,
"receiverOptions" => array(
array(
"receiver" => array("email" => $r1_email),
"invoiceData" => array(
"item" => array(
array(
array(
"name" => $product_name,
"price" => $r1_amount,
"identifier" => $indentifier
)
)
)
)
),
array(
"receiver" => array("email" => $r2_email),
"invoiceData" => array(
"item" => array(
array(
array(
"name" => "product 2",
"price" => $r2_amount,
"identifier" => "p2"
)
)
)
)
)
)
);
$response = $this->_paypalSend($detailsPack, "SetPaymentOptions");
$dets = $this->getPaymentOptions($paykey);
return $this->paypalUrl.$paykey;
}
}
这是我得到的回应,
array(3) { ["responseEnvelope"]=> array(4) { ["timestamp"]=> string(29) "2015-06-04T14:04:07.395-07:00" ["ack"]=> string(7) "Success" ["correlationId"]=> string(13) "6c472863c4053" ["build"]=> string(8) "15743565" } ["payKey"]=> string(20) "AP-5LN44020A0587750B" ["paymentExecStatus"]=> string(7) "CREATED" }
哪个非常好,我可以使用paykey,但ipnNotificationUrl无法正常工作。它不会在URL上发送任何内容。
试图解决这个问题,
1)确实改变了ipnNotificationUrl的URL,甚至做了硬编码
2)用IPN模拟器(听众)测试,为测试工作
3)更改了返回URL并取消了URL以测试其他人是否正常工作,同时确保我正在使用正确的文件和代码
请帮助!
答案 0 :(得分:0)
代码工作正常,但不是因为paypal已将IPN排队等待。
此处有更多详情https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNOperations/
希望这个答案能够帮助他人。