通过paypal快速结账重复订阅,买家支付两次

时间:2015-10-07 06:33:17

标签: express paypal checkout recurring

我在我的网站上为每月订阅创建了定期付款。用户每个月都会付钱。但是我看到买家的订阅费用是两次,一次是发起,一次是重复。 我读了https://developer.paypal.com/docs/classic/api/merchant/DoExpressCheckoutPayment_API_Operation_NVP/,我们可以在此设置PAYMENTREQUEST_n_AMT = 0和SetExpressCheckout来忽略发起付款。但是当我将它设置为0时,我得到的错误是amout为零所以我可以完成结账。 我怎样才能创建无偿两次的经常性复发。我试过跳过DoExpressCheckoutPayment方法,但通过这种方式,我无法获得交易ID

2 个答案:

答案 0 :(得分:1)

当您创建定期付款时,您可以选择向用户收取两次费用 - 其中一项与INITAMT参数相关,并且会立即从用户帐户收取费用。第二个与BILLINGPERIOD,BILLINGFREQUENCY,TOTALBILLINGCYCLES和REGULARTOTALBILLINGCYCLES paypal参数有关,这与当前时间段内的经常性付款 AFTER 有关。关键是在经常性的一段时间后设置付款并设置INITAMT以立即获得第一笔付款

对于(PHP)示例:

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

在定期付款中,没有交易ID,但在您的情况下,现有的订阅ID将为PROFILEID + CORRELATIONID

答案 1 :(得分:1)

以下是我的应用程序代码,首先我调用setExpressCheckout()而不是getExpressCheckoutDetails()

而不是使用这段代码收到令牌来支付和生成个人资料

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