Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从PayPal获取自适应支付的支付API密钥_Php_Cakephp_Paypal_Paypal Adaptive Payments - Fatal编程技术网

Php 如何从PayPal获取自适应支付的支付API密钥

Php 如何从PayPal获取自适应支付的支付API密钥,php,cakephp,paypal,paypal-adaptive-payments,Php,Cakephp,Paypal,Paypal Adaptive Payments,我绞尽脑汁想得到这份工作,但无法理解。我必须在使用cakephp框架创建的webapp中使用自适应支付。我有API凭据,如API用户名、密码和签名。但我面临的主要问题是如何调用payapi来获取API密钥,这是实现此功能所需的第一件事。我是新来的,所以我对这方面没有太多的知识,在谷歌做了大量的挖掘之后,我问了这个问题。有人能给出使用自适应支付的步骤吗 提前感谢您的帮助 您只需遵循三个步骤: 1-您向PayPal发送PayRequest消息 {“返回URL”:http://example.com/

我绞尽脑汁想得到这份工作,但无法理解。我必须在使用cakephp框架创建的webapp中使用自适应支付。我有API凭据,如API用户名、密码和签名。但我面临的主要问题是如何调用payapi来获取API密钥,这是实现此功能所需的第一件事。我是新来的,所以我对这方面没有太多的知识,在谷歌做了大量的挖掘之后,我问了这个问题。有人能给出使用自适应支付的步骤吗


提前感谢您的帮助

您只需遵循三个步骤:

1-您向PayPal发送PayRequest消息

{“返回URL”:http://example.com/returnURL.htm“,\“requestEnvelope”:{“errorLanguage”:“en_US”},“currencyCode”:“USD”,\“接收者名单”:{“接收者”:[{“电子邮件”:”david@example.com", \ “金额”:“10.00”,}]},“取消URL”:http://example.com/cancelURL.htm“,\”操作类型“:“支付”}

2-您收到带有支付密钥的响应

{“响应开发”:\{“时间戳”:“2009-10-06T14:30:39.383-07:00”,“确认”:“成功”,“关联ID”:“cfe8f8783f1d3”,“构建”:“开发”},“付款键”:“AP-17266198048308436”,“付款执行状态”:“已创建”}

3-您必须将发件人的浏览器重定向到PayPal才能批准付款

这是步骤1的示例代码(它在我的本地服务器上工作):



这里有很多例子:

您只需遵循三个步骤:

1-您向PayPal发送PayRequest消息

{“返回URL”:http://example.com/returnURL.htm“,\“requestEnvelope”:{“errorLanguage”:“en_US”},“currencyCode”:“USD”,\“接收者名单”:{“接收者”:[{“电子邮件”:”david@example.com", \ “金额”:“10.00”,}]},“取消URL”:http://example.com/cancelURL.htm“,\”操作类型“:“支付”}

2-您收到带有支付密钥的响应

{“响应开发”:\{“时间戳”:“2009-10-06T14:30:39.383-07:00”,“确认”:“成功”,“关联ID”:“cfe8f8783f1d3”,“构建”:“开发”},“付款键”:“AP-17266198048308436”,“付款执行状态”:“已创建”}

3-您必须将发件人的浏览器重定向到PayPal才能批准付款

这是步骤1的示例代码(它在我的本地服务器上工作):



这里有很多例子:

可能重复我试图使用以下链接中的代码,做了必要的更改,但它给出了错误,即stream\u get\u contents()希望参数1是resource,boolean给定的。我该怎么办?前面的
fopen()
调用成功了吗?fopen返回false这就是它返回布尔值并引发异常的原因。因此上下文或URL需要修复。应该很容易找到。可能是重复的。我尝试使用以下链接中的代码,做了必要的更改,但它给出了错误,即stream_get_contents()希望参数1是资源,给定布尔值。我该怎么办?前面的
fopen()
调用成功了吗?fopen返回false这就是它返回布尔值并引发异常的原因。因此上下文或URL需要修复。应该很容易找到。我使用了相同的代码,但主要问题是我的php.ini文件中没有启用SSL,这在获取密钥时造成了问题!谢谢你的帮助!我使用了相同的代码,但主要问题是我的php.ini文件中没有启用SSL,这在获取密钥时产生了问题!谢谢你的帮助!
<?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()."||";
}

?>