2011-09-23 33 views
0

我想實現直接付款方式,因爲我有我的數據庫中的用戶的信用卡信息等。這就是我所說的樣品:如何更改此代碼以處理重複付款?

using System; 
using System.Collections.Generic; 
using System.Text; 
using com.paypal.sdk.services; 
using com.paypal.sdk.profiles; 
using com.paypal.sdk.util; 
using com.paypal.soap.api; 

namespace ASPDotNetSamples 
{ 
    public class DoDirectPayment 
    { 
     public DoDirectPayment() 
     { 
     } 
     public string DoDirectPaymentCode(string paymentAction, string amount, string creditCardType, string creditCardNumber, string expdate_month, string cvv2Number, string firstName, string lastName, string address1, string city, string state, string zip, string countryCode, string currencyCode) 
     { 

      com.paypal.soap.api.DoDirectPaymentReq req = new com.paypal.soap.api.DoDirectPaymentReq(); 


      NVPCallerServices caller = new NVPCallerServices(); 
      IAPIProfile profile = ProfileFactory.createSignatureAPIProfile(); 
      /* 
      WARNING: Do not embed plaintext credentials in your application code. 
      Doing so is insecure and against best practices. 
      Your API credentials must be handled securely. Please consider 
      encrypting them for use in any production environment, and ensure 
      that only authorized individuals may view or modify them. 
      */ 

      // Set up your API credentials, PayPal end point, API operation and version. 
      profile.APIUsername = "sdk-three_api1.sdk.com"; 
      profile.APIPassword = "QFZCWN5HZM8VBG7Q"; 
      profile.APISignature = "AVGidzoSQiGWu.lGj3z15HLczXaaAcK6imHawrjefqgclVwBe8imgCHZ"; 
      profile.Environment = "sandbox"; 
      caller.APIProfile = profile; 

      NVPCodec encoder = new NVPCodec(); 
      encoder["VERSION"] = "51.0"; 
      encoder["METHOD"] = "DoDirectPayment"; 

      // Add request-specific fields to the request. 
      encoder["PAYMENTACTION"] = paymentAction; 
      encoder["AMT"] = amount; 
      encoder["CREDITCARDTYPE"] = creditCardType; 
      encoder["ACCT"] = creditCardNumber; 
      encoder["EXPDATE"] = expdate_month; 
      encoder["CVV2"] = cvv2Number; 
      encoder["FIRSTNAME"] = firstName; 
      encoder["LASTNAME"] = lastName; 
      encoder["STREET"] = address1; 
      encoder["CITY"] = city; 
      encoder["STATE"] = state; 
      encoder["ZIP"] = zip; 
      encoder["COUNTRYCODE"] = countryCode; 
      encoder["CURRENCYCODE"] = currencyCode; 

      // Execute the API operation and obtain the response. 
      string pStrrequestforNvp = encoder.Encode(); 
      string pStresponsenvp = caller.Call(pStrrequestforNvp); 

      NVPCodec decoder = new NVPCodec(); 
      decoder.Decode(pStresponsenvp); 
      return decoder["ACK"]; 

     } 
    } 
} 

這是鏈接:

https://cms.paypal.com/cms_content/US/en_US/files/developer/nvp_DoDirectPayment_cs.txt

這工作得很好,但我唯一的問題是如何處理recurringpayment這個?我應該在樣本中做什麼改變?

感謝提前:)

+0

如果你有自己的信用卡細節,爲什麼不打電話給你的常規方法每個月?? (或者任何頻率...) –

+1

這是一個好主意。但是,它要求我在自己的一端創建Windows服務或任何此類應用程序並處理線程等。如果我的線程在適當的時候錯過運行,該怎麼辦?付款是一項關鍵功能,我不想把它搞砸。而不是我認爲將這個過程委託給PayPal是明智的。 – Jaggu

回答