1

我使用 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 ");
        }
    }           
}
4

1 回答 1

0

我没有看到您通过 DoExpressCheckout 调用完成交易。

看起来您正在执行 SetExpressCheckout,它将为您提供付款人 ID 和快速结帐令牌。你在 URL 中得到这个:

http://example.com/Store/ReturnPaypal/?token=EC-8F726826L7777777&PayerID=PEWR9EA

令牌=EC-8F726826L7777777

付款人 ID=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']); 
}
?>
于 2015-07-27T23:00:17.207 回答