我想实现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 Priya
答案 0 :(得分: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);
}
}
答案 1 :(得分:0)
您需要对DoCapture
API call进行API调用。
如果您之前未使用过PayPal的API调用,我建议您也阅读Getting Started guide。
答案 2 :(得分: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");
}
}