Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Paypal: Create Recurring Payments Profile Working Code

    • 0
    • 1
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 1.14k
    Comment on it

    This code use to deduct amount automatically from paypal buyers account. It is something like advance payment mode. If user agree with automatically deduction when he / she paying through paypal then amount will deduct according to billing period.

    //step1. include paypal.class.php file (find attached file)

      include_once('paypal.class.php');
      $objPaypal  =   new MyPayPal();
    
      $PayPalMode         = 'sandbox'; // sandbox or live
        $PayPalApiUsername         = 'xxxxxxxxx'; //PayPal API Username
        $PayPalApiPassword         = 'xxxxxxxxx'; //Paypal API password
        $PayPalApiSignature     = 'xxxxxxxx'; //Paypal API Signature
        $PayPalCurrencyCode     = 'USD'; //Paypal Currency Code
        $PayPalReturnURL         = 'http://localhost/payapl_requirring/createRecurringPaymentsProfile.php'; //Point to process.php page
        $PayPalCancelURL         = 'http://localhost/payapl_requirring/cancel_url.php'; //Cancel URL if user clicks cancel
    

    //step 2.

        $padata =     '&METHOD=SetExpressCheckout'.
                    '&RETURNURL='.urlencode($PayPalReturnURL).
                    '&CANCELURL='.urlencode($PayPalCancelURL).
                    '&PAYMENTREQUEST_0_PAYMENTACTION='.urlencode("Authorization").
                    '&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital'.
                    '&L_PAYMENTREQUEST_0_NAME0=xyz'.
                    '&L_PAYMENTREQUEST_0_NUMBER0=132456'.
            '&L_PAYMENTREQUEST_0_DESC0=xyz'.
                    '&L_PAYMENTREQUEST_0_AMT0=12'.
            '&L_PAYMENTREQUEST_0_QTY0=1'.
                    '&PAYMENTREQUEST_0_AMT=12'.
                    '&L_BILLINGTYPE0=RecurringPayments'.
                    '&L_BILLINGAGREEMENTDESCRIPTION0=12.00 per month';
                    //'&L_PAYMENTTYPE0 = Any';
    
        $request    =   $objPaypal->PPHttpPost('SetExpressCheckout', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);
    

    //step 3. redirect to checkout page.

        $request    =   explode('&',$request);
        $request    =   explode('=',$request[0]);
        $token      =   $request[1];
    
        $paypalurl ='https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$token.'';
    
        header('Location: '.$paypalurl);
    
    //step4. create file createRecurringPaymentsProfile.php and enter below code
    
    include_once('paypal.class.php');
    
        $objPaypal  =   new MyPayPal();
    
        $PayPalMode         = 'sandbox'; // sandbox or live
        $PayPalApiUsername         = 'xxxxxxxxx'; //PayPal API Username
        $PayPalApiPassword         = 'xxxxxxxxx'; //Paypal API password
        $PayPalApiSignature     = 'xxxxxxxx'; //Paypal API Signature
        $PayPalCurrencyCode     = 'USD'; //Paypal Currency Code
    
        $paypalmode     =   ($PayPalMode=='sandbox') ? '.sandbox' : '';
    
        $padata         =   '&Method=GetExpressCheckoutDetails&TOKEN='.$_GET['token'];
    
        $request    =   $objPaypal->PPHttpPost('GetExpressCheckoutDetails', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);
    
        $request    =   explode('&', $request);
            $arrData    =   array();
        foreach($request as $payData){
            $payData                    =   explode('=',$payData);
            $arrData[$payData[0]]       =   $payData[1];      
        }
    
    
        if(!empty($arrData)){
        $padata =     '&TOKEN='.urlencode($_GET['token']).
            '&PAYERID='.urlencode($_GET['PayerID']).
            '&PAYMENTREQUEST_0_PAYMENTACTION='.urlencode("SALE").
                    '&BUTTONSOURCE  =  AngellFreeInc_USBSwiper_EC_US'.
    
            //set item info here, otherwise we won't see product details later  
                    '&L_PAYMENTREQUEST_0_NAME0=xyz'.
                                    '&L_PAYMENTREQUEST_0_NUMBER0=132456'.
                                    '&L_PAYMENTREQUEST_0_DESC0=asfasdfsf'.
                                    '&L_PAYMENTREQUEST_0_AMT0=12'.
                                    '&L_PAYMENTREQUEST_0_QTY0=1'.               
    
                                    '&PAYMENTREQUEST_0_ITEMAMT=12'.
                                    '&PAYMENTREQUEST_0_TAXAMT=0'.
                                    '&PAYMENTREQUEST_0_SHIPPINGAMT=0'.
                                    '&PAYMENTREQUEST_0_HANDLINGAMT=0'.
                                    '&PAYMENTREQUEST_0_SHIPDISCAMT=0'.
                                    '&PAYMENTREQUEST_0_INSURANCEAMT=0'.
                                    '&PAYMENTREQUEST_0_AMT=12'.
                                    '&PAYMENTREQUEST_0_CURRENCYCODE='.urlencode($PayPalCurrencyCode);
    
    
        $request    =   $objPaypal->PPHttpPost('DoExpressCheckoutPayment', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);
    
        $request    =   explode('&', $request);
            $arrData1    =   array();
        foreach($request as $payData){
            $payData                    =   explode('=',$payData);
            $arrData1[$payData[0]]       =   $payData[1];      
        }
    
            if(!empty($arrData1)){
                    $date = (date('d')+1);
    
                    $padata =  '&TOKEN='.urlencode($_GET['token']).'&PROFILESTARTDATE='.urlencode( date("Y-m-").$date .'T'.date("H:i:s"). 'Z' ).'&DESC=12.00 per month&BILLINGPERIOD=Month&BILLINGFREQUENCY=12&AMT=12.00&CURRENCYCODE=USD&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital&L_PAYMENTREQUEST_0_NAME0=xyz&L_PAYMENTREQUEST_0_DESC0=asfasdfsf&L_PAYMENTREQUEST_0_AMT0=12.00&L_PAYMENTREQUEST_0_QTY0=1&EMAIL=harryalm54@gmail.com';
    
                    $request    =   $objPaypal->PPHttpPost('CreateRecurringPaymentsProfile', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);
                    $request    =   explode('&', $request);
                    $arrData1   =   array();
                    foreach($request as $payData){
                        $payData                    =   explode('=',$payData);
                        $arrData1[$payData[0]]       =   urldecode($payData[1]);      
                    }
    
                    print_r($arrData1);
    
    
            }
    
            //step last
        }
    
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: