我在我的网站上创建了每月订阅的定期付款。用户将每月付款。但我看到买家为订阅支付了两次费用,一次用于启动,一次用于重复。 我读了https://developer.paypal.com/docs/classic/api/merchant/DoExpressCheckoutPayment_API_Operation_NVP/ ,我们可以在此设置 PAYMENTREQUEST_n_AMT = 0 和 SetExpressCheckout 以忽略发起付款。但是当我将它设置为 0 时,我会收到金额为零的错误消息,因此我可以完成结帐。 我怎样才能创建无偿重复两次。我尝试跳过 DoExpressCheckoutPayment 方法,但是通过这种方式,我无法获取交易 ID
最佳答案
以下是我的应用程序代码,首先我调用 setExpressCheckout()
而不是 getExpressCheckoutDetails()
比使用这段代码支付和生成个人资料收到 token
if(request.getParameter("token")!= null && request.getParameter("PayerID") != null){
if(token.contentEquals(request.getParameter("token"))/* && payerID.contentEquals(request.getParameter("PayerID"))*/){
this.payerID = request.getParameter("PayerID");
if(doExpressCheckout()){
if(createRecurringProfile()){
//some notification showing successful order
log.debug("Trasaction status : Successfull");
license.setProfileID(profileID);
license.setActive(true);
license.setLicenseType(LicenseBean.PAYMENT_RECURRING);
ApplicationInstance.getCurrent().fireEvent("SaveLicense", description, license,false);
ApplicationInstance.getCurrent().fireEvent("DisplayLicenseDetails", "Success", license,false);
}
以下是四种方法
public String setExpressCheckout() {
NVPEncoder encoder = new NVPEncoder();
NVPDecoder decoder = new NVPDecoder();
try
{
encoder.add("VERSION", "86.0");
encoder.add("METHOD","SetExpressCheckout");
encoder.add("L_BILLINGTYPE0","RecurringPayments");
encoder.add("L_BILLINGAGREEMENTDESCRIPTION0","UserPack");
// Add request-specific fields to the request string.
encoder.add("RETURNURL",returnURL);
encoder.add("CANCELURL",cancelURL);
encoder.add("AMT",cost);
encoder.add("PAYMENTACTION",paymentAction.getValue());
encoder.add("CURRENCYCODE",currencyCode.getValue());
// Execute the API operation and obtain the response.
String NVPRequest= encoder.encode();
String NVPResponse =caller.call(NVPRequest);
decoder.decode(NVPResponse);
}
catch(PayPalException pe){
log.error("Paypal Exception:", pe.getCause());
}
catch (Exception ex)
{
log.error(ex);
}
return decoder.get("TOKEN");
}
public boolean getExpressCheckoutDetails(String token)
{
NVPEncoder encoder = new NVPEncoder();
NVPDecoder decoder = new NVPDecoder();
try
{
encoder.add("VERSION", "86.0");
encoder.add("METHOD", "GetExpressCheckoutDetails");
// Add request-specific fields to the request string.
// Pass the token value returned in SetExpressCheckout.
encoder.add("TOKEN", token);
// Execute the API operation and obtain the response.
String NVPRequest = encoder.encode();
String NVPResponse = caller.call(NVPRequest);
decoder.decode(NVPResponse);
// payerID = decoder.get("PAYERID");
payerName = decoder.get("PAYERNAME");
}catch (Exception ex)
{
log.error(ex);
}
if(decoder.get("ACK").toLowerCase().contains("success")){
this.token = token;
return true;
}
else{
return false;
}
}
public boolean createRecurringProfile()
{
NVPEncoder encoder = new NVPEncoder();
NVPDecoder decoder = new NVPDecoder();
try
{
encoder.add("VERSION", "86.0");
encoder.add("METHOD","CreateRecurringPaymentsProfile");
encoder.add("DESC","UserPack");// #Profile description - same as billing agreement description
encoder.add("BILLINGPERIOD","Month");// #Period of time between billings
encoder.add("BILLINGFREQUENCY","1");// #Frequency of charges
// encoder.add("INITAMT","25.29");
// encoder.add("FAILEDINITAMTACTION","ContinueOnFailure");
// Add request-specific fields to the request string.
// Pass the token value by actual value returned in the SetExpressCheckout.
encoder.add("TOKEN",token);
encoder.add("PAYERID",payerID);
Date localTime = new Date();
//creating DateFormat for converting time from local timezone to GMT(as specified in paypal)
DateFormat converter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
encoder.add("PROFILESTARTDATE",converter.format(localTime));//SimpleDateFormat.getTimeInstance().format(new Date())
encoder.add("AMT",cost);
encoder.add("CURRENCYCODE","USD");// #The currency, e.g. US dollars
encoder.add("COUNTRYCODE","US");// #The country code, e.g. US
encoder.add("MAXFAILEDPAYMENTS","3");
// encoder.add("PAYMENTACTION",paymentAction.getValue());
encoder.add("CURRENCYCODE",currencyCode.getValue());
// Execute the API operation and obtain the response.
String NVPRequest = encoder.encode();
String NVPResponse =caller.call(NVPRequest);
decoder.decode(NVPResponse);
profileID = decoder.get("PROFILEID");
profileStatus = decoder.get("PROFILESTATUS");
//transactionID = decoder.get("TRANSACTIONID");
paymentDate = decoder.get("PAYMENTDATE");
log.debug("Paypal acknowledgement: "+decoder.get("ACK"));
//System.out.println("Paypal acknowledgement: "+decoder.get("ACK"));
}
catch(PayPalException pe){
log.error("Paypal Exception:", pe.getCause());
}
catch(Exception ex)
{
log.error("Error :",ex.getCause());
}
if(decoder.get("ACK").toLowerCase().contains("success")){
return true;
}
else{
//System.out.println("Paypal error: "+decoder.get("L_SHORTMESSAGE0"));
log.error("Paypal error: "+decoder.get("L_SHORTMESSAGE0"));
return false;
}
}
public boolean doExpressCheckout()
{
NVPEncoder encoder = new NVPEncoder();
NVPDecoder decoder = new NVPDecoder();
try
{
encoder.add("VERSION", "51.0");
encoder.add("METHOD","DoExpressCheckoutPayment");
// Add request-specific fields to the request string.
// Pass the token value by actual value returned in the SetExpressCheckout.
encoder.add("TOKEN",token);
encoder.add("PAYERID",payerID);
encoder.add("AMT",cost);
encoder.add("PAYMENTACTION",paymentAction.getValue());
encoder.add("CURRENCYCODE",currencyCode.getValue());
// Execute the API operation and obtain the response.
String NVPRequest = encoder.encode();
String NVPResponse =caller.call(NVPRequest);
decoder.decode(NVPResponse);
//transactionID = decoder.get("TRANSACTIONID");
paymentDate = decoder.get("PAYMENTDATE");
log.debug("Paypal acknowledgement: "+decoder.get("ACK"));
//System.out.println("Paypal acknowledgement: "+decoder.get("ACK"));
}
catch(PayPalException pe){
log.error("Paypal Exception:", pe.getCause());
}
catch(Exception ex)
{
log.error("Error :",ex.getCause());
}
if(decoder.get("ACK").toLowerCase().contains("success")){
return true;
}
else{
//System.out.println("Paypal error: "+decoder.get("L_SHORTMESSAGE0"));
log.error("Paypal error: "+decoder.get("L_SHORTMESSAGE0"));
return false;
}
}
关于express - 通过 paypal 快速结账定期订阅,买家支付两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32985243/