我使用Paypal付款的方法不起作用。用户到达Paypal页面后,其中包含他所购买的内容的描述,然后将其发送到我的网站,该网站上显示付款成功
http://example.com/Store/ReturnPaypal/?token=EC-8F726826L7777777&PayerID=PEWR9EA
但是当我访问我的PayPal帐户时,我看不到任何额外的钱
public ActionResult OrderPaypal()
{
string api_paypal = "https://api-3t.paypal.com/nvp?";
string user = "info_api1.example.com";
string pass = "testpass";
string signature = "test.test-test";
string version = "124.0";
string requete = api_paypal + "VERSION=" + version + "&USER=" + user + "&PWD=" + pass + "&SIGNATURE=" + signature;
requete = requete + "&METHOD=SetExpressCheckout" +
"&CANCELURL=" + HttpUtility.UrlEncode("http://example.com/Store/CancelPaypal/") +
"&RETURNURL=" + HttpUtility.UrlEncode("http://example.com/Store/ReturnPaypal/") +
"&AMT=" + SessionData.CurrentOrder.Total.ToString().Replace(',','.') +
"&CURRENCYCODE=EUR" +
"&DESC=" + HttpUtility.UrlEncode("Paiement total:" + SessionData.CurrentOrder.Total+" €") +
"&LOCALECODE=FR" +
"&HDRIMG=" + HttpUtility.UrlEncode("http://example.com/assets/images/home/image_10000.png");
var httpWebRequest = (HttpWebRequest)WebRequest.Create(requete);
WebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
string rep = streamReader.ReadToEnd();
if (!string.IsNullOrEmpty(rep))
{
string[] list = rep.Split('&');
Dictionary<string,string> dicParam = new Dictionary<string,string>();
foreach(string str in list)
{
string key = str.Split('=')[0];
string value = str.Split('=')[1];
dicParam.Add(key, value);
}
if (dicParam["ACK"] == "Success")
return Redirect("https://www.paypal.com/webscr&cmd=_express-checkout&token=" + dicParam["TOKEN"]);
else
{
ViewBag.State = "-1";
return View("ReturnSolution",dicParam["L_SHORTMESSAGE0"]);
}
}
else
{
ViewBag.State = "-1";
return View("ReturnSolution", "Error communication PayPal ");
}
}
}
答案 0 :(得分:0)
我没有看到您使用DoExpressCheckout调用完成交易。
看起来您正在使用SetExpressCheckout,它将为您提供付款人ID和快速结账标记。你可以在URL中找到它:
http://example.com/Store/ReturnPaypal/?token=EC-8F726826L7777777&PayerID=PEWR9EA
标记= EC-8F726826L7777777
PayerID = PEWR9EA
这在URL中返回,用于完成DoExpressCheckout调用(我在代码中没有看到)。
以下是PHP中SetExpressCheckout和DoExpressCheckout的示例脚本。
<a href='http://marshalcurrier.com/paypal/ExpressCheckout/custom/SetDo.php'>RESET</a><br>
<form method='post'><input type="text" name="CHARGE" value="1"/><input type="submit" value="Pay Now"/><form>
<?php
session_start();
$PPUSER = 'marshal_api1.clubcovert.com';
$PPPWD = 'LL6NV7TDRB9RFXQ5';
$PPSIG = 'ANc3YRaMB1Tgm9TediH0gENHB02JAksSKWD08wVNN3w3pwHqdBW8Im6y';
function url(){ //PayPal Payment URL (TEST or LIVE)
$url = "https://api-3t.sandbox.paypal.com/nvp";
return $url;
}
function curlCall($nvp){ // Function for Curl Call to PayPal.
$url = url();
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($nvp) );
//echo http_build_query($nvp); //Print String
curl_setopt($ch, CURLOPT_URL, $url);
$server_output = curl_exec($ch);
mb_parse_str($server_output, $arr);
return $arr;
}
if(isset($_POST['CHARGE'])){ // SetExpressCheckout Call
$_SESSION['AMT'] = $_POST['CHARGE'];
$nvp = array(
'USER' => $PPUSER,
'PWD' => $PPPWD,
'SIGNATURE' => $PPSIG,
'METHOD' => 'SetExpressCheckout',
'VERSION' => '123',
'PAYMENTREQUEST_0_PAYMENTACTION' => 'SALE',
'PAYMENTREQUEST_0_AMT' => $_POST['CHARGE'],
'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
'RETURNURL' => 'http://marshalcurrier.com/paypal/ExpressCheckout/SetDo.php',
'CANCELURL' => 'http://marshalcurrier.com/paypal/ExpressCheckout/SetDo.php',
);
$arr = curlCall($nvp);
echo '<br><br>SetExpressCheckout Call to PayPal:<br><pre>';
print_r ($nvp);
echo '</pre>';
echo 'SetExpressCheckout Server Response:<br><pre>';
print_r ($arr);
echo '</pre>';
echo '<a href="https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.($arr['TOKEN']).'">Go To PayPal</a>';
}
if(isset($_GET['PayerID']) && (isset($_POST['CHARGE'])) == false){ // DoExpressCheckoutPayment Call
if (isset($_SESSION['AMT'])){
$AMT = $_SESSION['AMT'];
}else{
$AMT = null;
}
$nvp = array(
'METHOD' => 'DoExpressCheckoutPayment',
'VERSION' => '123',
'USER' => $PPUSER,
'PWD' => $PPPWD,
'SIGNATURE' => $PPSIG,
'PAYERID' => $_GET['PayerID'],
'TOKEN' => $_GET['token'],
'PAYMENTREQUEST_0_PAYMENTACTION' => 'SALE',
'PAYMENTREQUEST_0_AMT' => $AMT,
'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
);
$arr = curlCall($nvp);
echo '<br><br>DoExpressCheckoutPayment Call to PayPal:<br><pre>';
print_r ($nvp);
echo '</pre>';
echo 'DoExpressCheckoutPayment Server Response:<br><pre>';
print_r ($arr);
echo '</pre>';
unset($_SESSION['AMT']);
}
?>