使用托管页面快速结账和信用卡付款的Paypal高级重复计费

时间:2013-08-22 11:26:27

标签: c# asp.net-mvc paypal payment-gateway

在我的应用程序中,我需要使用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 };
    }
}

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

1)页面被重定向到顶层。这意味着浏览器窗口将重定向到IFrame网址。我选择了布局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"

这样可以正常工作并创建重复的配置文件。

然而,当我点击“Check with Paypal”按钮时,这将带我到Paypal页面,我可以使用我的Paypal凭据登录Paypal,然后当我点击“paynow”按钮时,它将扣除来自我账户的钱。这也有一个PNERF值,当我使用上面相同的代码将交易转换为重复的配置文件时,将Tender替换为P,但它显示了一条响应消息“未找到与此id对应的事务ID”。 Paypal结账流程不会显示有关用户进行重新付款部分的任何信息。

另外,我跟着Express Checkout with recurring billing来完成任务,但是在DoExpressCheckout步骤中我得到了BAID为null。

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

提前致谢。

1 个答案:

答案 0 :(得分: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请求PayPal付款。