2015-10-07 49 views
1

我在我的網站創建了每月訂閱的定期付款。用戶將每月付款。但是我發現買方支付了兩次訂閱費用,一次用於啓動,一次用於重複使用。 我看了https://developer.paypal.com/docs/classic/api/merchant/DoExpressCheckoutPayment_API_Operation_NVP/,我們可以在這個和SetExpressCheckout中設置PAYMENTREQUEST_n_AMT = 0來忽略啓動付款。但是,當我將它設置爲0時,我得到的錯誤是所有數都爲零,因此我可以完成結帳。 如何創建無限次的無限次循環。我嘗試跳過DoExpressCheckoutPayment方法,但通過這種方式,我無法獲得交易ID通過paypal快速結賬定期訂閱,買方支付兩次

+0

你設置任何初始確認金額,我也實施了定期付款,我還沒有遇到這樣的問題 – SSH

+0

不,我不要在我的CreateRecurringPaymentProfile方法中設置INITAMT。 這是參數I在SetExpressCheckout –

+0

通過下面是在DoExpressCheckoutPayment參數 $字段=陣列(\t \t \t \t \t \t 'TOKEN'=> $ checkoutDetails [ 'TOKEN'], \t \t 'PAYMENTACTION'=>「塞爾」, \t \t 'PAYERID'=> $ checkoutDetails [ 'PAYERID'], \t \t 'PAYMENTREQUEST_0_AMT'=> '5.0', \t \t 'PAYMENTREQUEST_0_CURRENCYCODE'=> 'NOK' \t \t); 並建立個人資料 $字段=陣列( \t 'TOKEN'=>進行urlencode($ checkoutDetails [ 'TOKEN']), \t 'PAYERID'=>進行urlencode($ checkoutDetails [ 'PAYERID']), \t「PROFILESTARTDATE '=>時間(), \t 'DESC'=> '測試', \t 'BILLINGPERIOD'=> '月', \t 'BILLINGFREQUENCY'=> '1', \t 'TOTALBILLINGCYCLES'=> '60' , \t'AMT'=>'5。0', \t'CURRENCYCODE'=>'NOK' \t \t); –

回答

1

當您創建定期付款時,您可以選擇向用戶收費兩次 - 其中一個與INITAMT參數相關,並且會立即從用戶收取費用帳戶。二是與BILLINGPERIOD,BILLINGFREQUENCY,TOTALBILLINGCYCLES和REGULARTOTALBILLINGCYCLES貝寶參數相關,這與定期付款AFTER當前時間段有關。關鍵是要設定的時間再現週期後付款,並設置INITAMT拿到首付款立即

對於(PHP)例如:

$padata['BILLINGPERIOD']     = 'Month'; 
$padata['BILLINGFREQUENCY']     = '1'; 
$padata['TOTALBILLINGCYCLES']    = '12'; 
$padata['REGULARTOTALBILLINGCYCLES']  = '1'; 
$padata['INITAMT']       = 'MONTHLY PRICE'; 

在定期付款沒有事務ID,但現有的訂閱你的情況ID此鍵將簡檔+的correlationID

+0

對不起,我想立即收取第一個循環。但我不想收費發起。如果我設置INITAMT,這意味着買方收取2次? –

+0

在這種情況下,必須像我的例子 – Pavel

+0

設置貝寶參數我試過,看到買家收取2倍這樣的http://pasteboard.co/1c2htGOT.png 但我希望它只收取一次。對不起,如果我誤解你的評論。 –

1

以下是我的應用程序代碼,首先我打電話setExpressCheckout()getExpressCheckoutDetails()

比在使用這塊令牌recieving支付和生成輪廓

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; 
    } 
}