8

在我的应用程序中,我需要使用 paypal advanced 设置定期计费部分,并且我正在使用 payflow 部分来做同样的事情。我需要使用 PayPal 支付按钮流程(快速结账流程)和信用卡付款来创建循环配置文件。我最初的要求是这样的:

public static PayPalRedirectAdv PayFlow()
{

    NameValueCollection requestArray = new NameValueCollection()
    {

        {"PARTNER", "PayPal"},             // You'll want to change these 4
        {"VENDOR", "merchantname"},           // To use your own credentials
        {"USER", "username"},
        {"PWD", "abcdenfg"},
        {"TRXTYPE", "A"},
        {"AMT", "1.00"},
        {"CURRENCY", "USD"},
        {"CREATESECURETOKEN", "Y"},
        {"SECURETOKENID", "tokenId generated"},  
        {"RETURNURL", UrlReturn}, 
        {"CANCELURL", UrlCancel},
        {"ERRORURL", lUrlError},
        {"BILLINGTYPE","RecurringBilling"}

    };

    NameValueCollection resp = run_payflow_call(requestArray); // Will call the payflow end point via HttpWebRequest
    if (resp["RESULT"] == "0")
    {
        string mode = "TEST";
        return new PayPalRedirectAdv
        {
            Url = "https://payflowlink.paypal.com?SECURETOKEN=" + resp["SECURETOKEN"] + "&SECURETOKENID=" + resp["SECURETOKENID"] + "&MODE=" + mode
        };
    }
    else
    {
        return new PayPalRedirectAdv { Url = string.Empty };
    }
}

该过程完成后,我将 url 设置为 IFrame,并将其嵌入到我的 mvc 项目中的一个视图中。加载 IFrame 时,它​​有两个问题。

1)页面被重定向到顶层。这意味着浏览器窗口被重定向到 IFrame url。我选择了布局 C 作为我的托管结帐页面。当我使用演示项目中提供的凭据时,浏览器导航就解决了;即 Iframe 在我的视图中正确加载。Paypal 管理器设置中是否有任何设置可以防止这种情况发生?我试图通过沙盒顶级导航来解决这个问题,但这不允许我通过单击“使用 Paypal 结帐”按钮重定向到 paypal 站点。

2) 对于使用信用卡付款,一旦交易成功,我将通过以下方式将现有交易转换为个人资料:

    "TRXTYPE=R&TENDER=C&PARTNER=PayPal&VENDOR=Acme&USER=Acme&PWD=a1b2c3d4&ACTION=A&PROFILENAME=RegularSubscription&ORIGID=<PNREF>&START=12012002&PAYPERIOD=
WEEK&TERM=12&OPTIONALTRX=S&OPTIONALTRXAMT=2.00&COMMENT1=First-time
customer&AMT=42.00"

这工作正常,并创建了重复配置文件。

但是,当我点击“使用 Paypal 结账”按钮时,这将带我进入 Paypal 页面,我可以使用我的 Paypal 凭据登录到 Paypal,然后当我点击“paynow”按钮时,它会从我的账户中扣款帐户。这也有一个 PNERF 值,当我使用上面的相同代码通过将 Tender 替换为 P 来将事务转换为循环配置文件时,但它向我显示了一条响应消息,即“找不到与此 id 对应的事务 id”。Paypal 结帐流程不显示有关用户将进行定期付款部分的任何信息。

此外,我按照Express Checkout 定期计费来完成任务,但在 DoExpressCheckout 步骤中我将 BAID 设为空。

我需要在我的网站上使用 paypal 付款和使用信用选项付款,那么我应该使用哪些参数来完成此操作?

提前致谢。

4

1 回答 1

1
string strUsername = "<<paypal_username>>";
    string strPassword = "<<paypal_password>>";
    string strSignature = "<<paypal_signature>>";
    string strCredentials = "USER=" + strUsername + "&PWD=" + strPassword + "&SIGNATURE=" + strSignature;

    string strNVPSandboxServer = "https://api-3t.sandbox.paypal.com/nvp";
    string strAPIVersion = "2.3";
    //4456193676582624                                                                   4025609244685781
    string strNVP = strCredentials + "&METHOD=DoDirectPayment" +
        "&CREDITCARDTYPE=VISA" +
         "&ACCT=<<CARDNO>>" +
         "&EXPDATE=<<EXPDATE>>" +
         "&CVV2=<<CVV>" +
         "&AMT=<<AMOUNT>>" +
         "&FIRSTNAME=<<CUST_NAME>>" +
         "&LASTNAME=<<CUST_LASTNAME>>" +
         "&CURRENCYCODE=<<CURRENCY_CODE>>" +
         "&IPADDRESS=<<USER_IP>>" +
         "&STREET=<<ADDRESS>>" +
         "&CITY=<<CITY>>" +
         "&STATE=<<STATE>>" +
         "&COUNTRY=<<COUNTRY>>" +
         "&ZIP=<<XIPCODE>>" +
         "&COUNTRYCODE=<<COUNTRY>>" +
         "&PAYMENTACTION=SALE" +
         "&L_NAME0=item1&L_DESC0=test1description&L_AMT0=1&L_QTY0=1" +
         "&L_NAME1=item2&L_DESC1=test2description&L_AMT1=2&L_QTY1=2" +
         "&L_NAME2=item3&L_DESC2=test3description&L_AMT2=3&L_QTY2=3" +
         "&VERSION=" + strAPIVersion;
    //strNVP = Server.UrlEncode(strNVP);
    try
    {
        //Create web request and web response objects, make sure you using the correct server (sandbox/live)
        HttpWebRequest wrWebRequest = (HttpWebRequest)WebRequest.Create(strNVPSandboxServer);
        wrWebRequest.Method = "POST";
        StreamWriter requestWriter = new StreamWriter(wrWebRequest.GetRequestStream());
        requestWriter.Write(strNVP);
        requestWriter.Close();

        // Get the response.
        HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();
        StreamReader responseReader = new StreamReader(wrWebRequest.GetResponse().GetResponseStream());

        //and read the response
        string responseData = responseReader.ReadToEnd();
        responseReader.Close();

        string result = Server.UrlDecode(responseData);

        string[] arrResult = result.Split('&');
        Hashtable htResponse = new Hashtable();
        string[] responseItemArray;
        foreach (string responseItem in arrResult)
        {
            responseItemArray = responseItem.Split('=');
            htResponse.Add(responseItemArray[0], responseItemArray[1]);
        }

        string strAck = htResponse["ACK"].ToString();

        if (strAck == "Success" || strAck == "SuccessWithWarning")
        {
            string strAmt = htResponse["AMT"].ToString();
            string strCcy = htResponse["CURRENCYCODE"].ToString();
            string strTransactionID = htResponse["TRANSACTIONID"].ToString();
            //ordersDataSource.InsertParameters["TransactionID"].DefaultValue = strTransactionID;

            string strSuccess = "Thank you, your order for: $" + strAmt + " " + strCcy + " has been processed.";
            Response.Write(strSuccess);
            //successLabel.Text = strSuccess;
        }
        else
        {
            string strErr = "Error: " + htResponse["L_LONGMESSAGE0"].ToString();
            string strErrcode = "Error code: " + htResponse["L_ERRORCODE0"].ToString();
            //errLabel.Text = strErr;
            //errcodeLabel.Text = strErrcode;
            return;
        }
    }
    catch (Exception ex)
    {
        // do something to catch the error, like write to a log file.
        Response.Write("error processing");
    }`enter code here`

尝试使用此代码....无需 DLL 即可请求贝宝付款。

于 2014-04-25T14:02:40.940 回答