[英]How to obtain Pay API key from PayPal for Adaptive Payments
I am at my wits end trying to get this work but cant understand it. 我竭尽全力试图完成这项工作,但无法理解。 I have to use Adaptive payments in a webapp which is created using cakephp framework.
我必须在使用cakephp框架创建的web应用程序中使用自适应支付。 I have API credentials like API Username, Password and Signature.
我有API凭证,例如API用户名,密码和签名。 But the main problem i am facing is how to call the Pay API to get the API key which is the first thing required to make this work.
但是我面临的主要问题是如何调用Pay API来获取API密钥,这是使这项工作必需的第一件事。 I am new to this so i dont have much knowledge about this and after lot digging in google i am asking this question.
我是新来的,所以我对此没有太多的了解,在谷歌大量挖掘后,我问这个问题。 Can someone please give steps for using Adaptive Payments..
有人可以给出使用自适应支付的步骤。
Thanks in advance for your help! 在此先感谢您的帮助!
You have to follow only three steps: 您只需要遵循三个步骤:
1- You send a PayRequest message to PayPal 1-您向PayPal发送PayRequest消息
{"returnUrl":"http://example.com/returnURL.htm", \\ "requestEnvelope":{"errorLanguage":"en_US"},"currencyCode":"USD", \\ "receiverList":{"receiver":[{"email":"david@example.com", \\ "amount":"10.00",}]},"cancelUrl":"http://example.com/cancelURL.htm",\\ "actionType":"PAY"}
{“ returnUrl”:“ http://example.com/returnURL.htm”,\\“ requestEnvelope”:{“ errorLanguage”:“ en_US”},“ currencyCode”:“ USD”,\\“ receiverList”:{“ receiver “:[{”电子邮件“:” david@example.com“,\\”数量“:” 10.00“,}]},” cancelUrl“:” http://example.com/cancelURL.htm“,\\” actionType “:“工资”}
2- You receive a response with a pay key. 2-您收到带有支付密钥的回复。
{"responseEnvelope":\\ {"timestamp":"2009-10-06T14:30:39.383-07:00","ack":"Success",\\ "correlationId":"cfe8f8783f1d3","build":"DEV"},\\ "payKey":"AP-17266198048308436","paymentExecStatus":"CREATED"}
{“ responseEnvelope”:\\ {“时间戳”:“ 2009-10-06T14:30:39.383-07:00”,“ ack”:“成功”,\\“ correlationId”:“ cfe8f8783f1d3”,“ build”:“ DEV “},\\” payKey“:” AP-17266198048308436“,” paymentExecStatus“:” CREATED“}
3- You must redirect the sender's browser to PayPal to approve the payment. 3-您必须将发件人的浏览器重定向到PayPal才能批准付款。
This would be an example code for step 1 (it works on my local server): 这将是第1步的示例代码(它在我的本地服务器上有效):
<?php
//turn php errors on
ini_set("track_errors", true);
//set PayPal Endpoint to sandbox
$url = trim("https://svcs.sandbox.paypal.com/AdaptivePayments/Pay");
$api_appid = 'APP-80W284485P519543T'; // para sandbox
//PayPal API Credentials
$API_UserName = "sbapi_1287090601_biz_api1.paypal.com"; //TODO
$API_Password = "1287090610"; //TODO
$API_Signature = "ANFgtzcGWolmjcm5vfrf07xVQ6B9AsoDvVryVxEQqezY85hChCfdBMvY"; //TODO
$receiver_email = "fake@email.com"; //TODO
$amount = 25; //TODO
//Default App ID for Sandbox
$API_AppID = "APP-80W284485P519543T";
$API_RequestFormat = "NV";
$API_ResponseFormat = "NV";
//Create request payload with minimum required parameters
$bodyparams = array ( "requestEnvelope.errorLanguage" => "en_US",
"actionType" => "PAY",
"cancelUrl" => "http://cancelUrl",
"returnUrl" => "http://returnUrl",
"currencyCode" => "EUR",
"receiverList.receiver.email" => $receiver_email,
"receiverList.receiver.amount" => $amount
);
// convert payload array into url encoded query string
$body_data = http_build_query($bodyparams, "", chr(38));
try
{
//create request and add headers
$params = array("http" => array(
"method" => "POST",
"content" => $body_data,
"header" => "X-PAYPAL-SECURITY-USERID: " . $API_UserName . "\r\n" .
"X-PAYPAL-SECURITY-SIGNATURE: " . $API_Signature . "\r\n" .
"X-PAYPAL-SECURITY-PASSWORD: " . $API_Password . "\r\n" .
"X-PAYPAL-APPLICATION-ID: " . $API_AppID . "\r\n" .
"X-PAYPAL-REQUEST-DATA-FORMAT: " . $API_RequestFormat . "\r\n" .
"X-PAYPAL-RESPONSE-DATA-FORMAT: " . $API_ResponseFormat . "\r\n"
));
//create stream context
$ctx = stream_context_create($params);
//open the stream and send request
$fp = @fopen($url, "r", false, $ctx);
//get response
$response = stream_get_contents($fp);
//check to see if stream is open
if ($response === false) {
throw new Exception("php error message = " . "$php_errormsg");
}
//close the stream
fclose($fp);
//parse the ap key from the response
$keyArray = explode("&", $response);
foreach ($keyArray as $rVal){
list($qKey, $qVal) = explode ("=", $rVal);
$kArray[$qKey] = $qVal;
}
//print the response to screen for testing purposes
If ( $kArray["responseEnvelope.ack"] == "Success") {
foreach ($kArray as $key =>$value){
echo $key . ": " .$value . "<br/>";
}
}
else {
echo 'ERROR Code: ' . $kArray["error(0).errorId"] . " <br/>";
echo 'ERROR Message: ' . urldecode($kArray["error(0).message"]) . " <br/>";
}
}
catch(Exception $e) {
echo "Message: ||" .$e->getMessage()."||";
}
?>
You have many examples here: https://www.x.com/developers/paypal/documentation-tools/paypal-code-samples 您在这里有很多示例: https : //www.x.com/developers/paypal/documentation-tools/paypal-code-samples
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.