在我的api中,我使用PHP代码自动将金额从一个沙箱 paypal 帐户转移到另一个沙箱 paypal 帐户。但是通过此PHP代码,无论是有效的还是无效的沙箱用户帐户都在进行交易,这些帐户根本不会发生。
此外,我找不到任何方法来检查我的代码是否接收者的沙盒帐户是否有效。如果它有效,则只能将资金转入收款人的帐户。
这是代码......
// Paypal_class.php
class Paypal {
public function __construct($username, $password, $signature) {
$this->username = urlencode($username);
$this->password = urlencode($password);
$this->signature = urlencode($signature);
$this->version = urlencode("122.0");
$this->api = "https://api-3t.sandbox.paypal.com/nvp";
//The functions can be modified but need to be urlencoded
$this->type = urlencode("EmailAddress");
$this->currency = urlencode("USD");
$this->subject = urlencode("Instant Paypal Payment");
}
public function pay($email, $amount, $note="Instant Payment") {
$string = "&EMAILSUBJECT=".$this->subject."&RECEIVERTYPE=".$this->type."&CURRENCYCODE=".$this->currency;
$string .= "&L_EMAIL0=".urlencode($email)."&L_Amt0=".urlencode($amount)."&L_NOTE0=".urlencode($note);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->api);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
$request = "METHOD=MassPay&VERSION=".$this->version."&PWD=".$this->password."&USER=".$this->username."&SIGNATURE=".$this->signature."$string";
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$httpResponse = curl_exec($ch);
if(!$httpResponse) {
exit("MassPay failed: ".curl_error($ch).'('.curl_errno($ch).')');
}
$httpResponseArray = explode("&", $httpResponse);
$httpParsedResponse = array();
foreach ($httpResponseArray as $i => $value) {
$tempArray = explode("=", $value);
if(sizeof($tempArray) > 1) {
$httpParsedResponse[$tempArray[0]] = $tempArray[1];
}
}
if((0 == sizeof($httpParsedResponse)) || !array_key_exists('ACK', $httpParsedResponse)) {
exit("Invalid HTTP Response for POST request($request) to ".$this->api);
}
return $httpParsedResponse;
}
}
?>
以下是我调用上述函数的代码.....
// pay.php
<?php
require "Paypal_class.php";
$paypal = new Paypal("xxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
$send_payment = $paypal->pay("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "10.00", "Thanks for an amazing service");
if("SUCCESS" == strtoupper($send_payment["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($send_payment["ACK"]))
{
exit('Pay Completed Successfully: '.print_r($send_payment, true));
}
else
{
exit('Pay failed: ' . print_r($send_payment, true));
}
?>
这里的问题是每当我点击这个api时,即使在输入错误或无效的帐户ID(沙盒)时也会发生金钱交易....任何人都可以帮我处理代码......我需要一个代码,其中我可以检查收款人的账户是否有效。如果没有,那么它不应该进行任何交易......而是必须返回&#34;失败&#34;回复中的消息。
请帮忙