【发布时间】:2020-06-13 12:20:56
【问题描述】:
我正在为 Paypal 自适应付款尝试此 (Method),第一部分运行良好,但在完成第二部分后没有任何反应,也没有查看错误。我知道这已经发布,但我查看了所有其他答案,但都是徒劳的。 我试图寻找其他选项来执行此功能,但它主要在“Ruby”或其他框架上可用,但我在 PHP
中需要它这是 PHP 代码
class PaypalTest{
public $app_id = "APP-80W284485P519543T";
public $apiUrl = 'https://svcs.sandbox.paypal.com/AdaptivePayments/';
public $paypalUrl="https://www.paypal.com/webscr?cmd=_ap-payment&paykey=";
public $headers;
function __construct(){
$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,
);
$this->envelope = array(
"errorLanguage" => "en_US",
"detailLevel" => "ReturnAll"
);
}
function getPaymentOptions($paykey){
$packet = array(
"requestEnvelope" => $this->envelope,
"paykey" => $paykey
);
return $this->_paypalSend($packet,"getPaymentOptions");
}
function setPaymentOptions(){
}
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;
}
function splitPay(){
// create the pay request
$createPacket = array(
"actionType" =>"PAY",
"currencyCode" => "USD",
"receiverList" => array(
"receiver" => array(
array(
"amount"=> "200.00",
"email"=>"sb-3oe0y636987@personal.example.com"
)
)
),
"returnUrl" => "http://test.local/payments/confirm",
"cancelUrl" => "http://test.local/payments/cancel",
"requestEnvelope" => $this->envelope
);
$response = $this->_paypalSend($createPacket,"Pay");
print_r($response);
$payKey = $response['payKey'];
$detailPacket = array(
"requestEnvelope" => $this->envelope,
"payKey" => $payKey,
"receiverOptions" => array(
array(
"receiver" => array("email"=>"sb-3oe0y636987@personal.example.com"),
"invoiceData" => array(
"item" => array(
array(
"name" => "Product 1",
"price" => "100.00",
"identifier" => "p1"
),
array(
"name" => "Product 2",
"price" => "100.00",
"identifier" => "p1"
)
)
)
)
)
);
$response = $this->_paypalSend($detailPacket,"setPaymentOptions");
echo $response;
print_r($response);
$dets = $this->getPaymentOptions($payKey);
print_r($dets);
}
}
$payment = new PaypalTest();
$payment->splitPay();
【问题讨论】:
-
您是否有用于自适应支付的实时应用 ID?这个问题可能没有实际意义,因为自适应支付非常老旧,不再支持新的集成。即使您确实让它在沙箱中工作,您也无法对此做任何事情。
-
还有其他类似的解决方案吗?
标签: paypal paypal-adaptive-payments