2013-08-05 69 views
1

我想實現paypal授權和自動捕獲付款。我已經使用貝寶標準賬戶。我已發送具有授權參數的付款請求。如何在PayPal標準中自動捕獲授權的PayPal付款?

<form:form commandName="paymentForm" id="paymentForm" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" name="paypal">   
    <form:input path="cmd" id="cmd" name="cmd" type="hidden" /> 
    <form:input path="business" id="business" name="business" type="hidden" /> 
    <form:input path="password" id="password" name="password" type="hidden" /> 
    <form:input path="custom" id="custom" name="custom" type="hidden" /> 
    <form:input path="item_name" id="item_name" name="item_name" type="hidden" />  
    <form:input path="amount" id="amount" name="amount" type="hidden" /> 
    <form:input path="currencyCode" type="hidden" name="currency_code" value="EUR" /> 
    <form:input path="rm" id="rm" name="rm" type="hidden" /> 
    <%-- <form:input path="returnUrl" id="return" name="return" type="hidden" /> --%>  
    <form:input type="hidden" name="return" value="${paymentForm.returnUrl}" /> 
    <form:input type="hidden" name="cancel_return" path="cancel_return" /> 
    <form:input type="hidden" name="cert_id" path="certId" /> 
    <form:input type="hidden" name="paymentaction" path="authorization"> 
</form:form>  

現在我想通過使用事務ID /授權ID向PayPal發送Http請求來捕獲付款。我怎樣才能做到這一點?

在此先感謝

K.Lakshmi普里亞

回答

1

下面的Java代碼讓使用DoCapture API調用

import com.paypal.sdk.core.nvp.NVPDecoder; 
import com.paypal.sdk.core.nvp.NVPEncoder; 
import com.paypal.sdk.exceptions.PayPalException; 
import com.paypal.sdk.profiles.APIProfile; 
import com.paypal.sdk.profiles.ProfileFactory; 
import com.paypal.sdk.services.NVPCallerServices; 

public class DoCapture {  
    public static final String DO_CAPTURE_METHOD = "DoCapture"; 

public static void main(String[] args) throws PayPalException { 

    APIProfile profile; 
    profile = ProfileFactory.createSignatureAPIProfile(); 
     profile.setAPIUsername("API User Name"); 
     profile.setAPIPassword("PWD"); 
     profile.setSignature("API Signature"); 
     // profile.setEnvironment("sandbox"); 
     // profile.setSubject(""); 
     // profile.setTimeout(timeout); 

    NVPEncoder encoder = new NVPEncoder(); 
NVPDecoder decoder = new NVPDecoder(); 

    NVPCallerServices caller = new NVPCallerServices(); 
    caller.setAPIProfile(profile); 

    encoder.add("METHOD", DO_CAPTURE_METHOD); 
    encoder.add("AUTHORIZATIONID", "8PR03910DP1572333"); 
    encoder.add("COMPLETETYPE", "Complete"); 
    encoder.add("AMT", "100"); 
    encoder.add("CURRENCYCODE", "EUR"); 

    String NVPRequest = encoder.encode(); 
    String NVPResponse = caller.call(NVPRequest); 
    decoder.decode(NVPResponse); 

    System.out.println("PayPal Response :: "+NVPResponse); 
} 
} 

有關更多詳細信息請參考https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/DoCapture_API_Operation_NVP/

0

在C#中,你可以使用下面的代碼捕獲支付捕獲授權支付。

public ActionResult CaptureAuthorization() 
    { 
     APIContext apiContext = Configuration.GetAPIContext(); 
     try 
     { 
      Authorization authorization = Authorization.Get(apiContext, "6SY29185GS4409204");//Provide Payment Id returned after authorizing payment. 
      Capture capture = new Capture(); 
      Amount captureAmount = new Amount(); 
      captureAmount.currency = "USD"; 
      captureAmount.total = "7"; 
      capture.amount = captureAmount; 

      Capture responseCap = authorization.Capture(apiContext, capture);//Capture Payment 

      if (responseCap.state.ToLower() != "completed") 
      { 
       return View("Failure"); 
      } 

      return View("Success"); 
     } 
     catch (Exception ex) 
     { 
      return View("Failure"); 
     } 
    }