how to call CreateRecurringPaymentsProfile after C

2019-09-08 16:34发布

I have downloaded and implemented this paypal integration lib on my website. https://github.com/hrendoh/PayPal-Express-Checkout-example

The recurring profiles are not getting created.

The function call for Express checkout is

  $resArray = CallShortcutExpressCheckout ($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL);
  $ack = strtoupper($resArray["ACK"]);
  if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
  {
  // if SetExpressCheckout is returned with success, move to paypal site for payments.
  RedirectToPayPal ( $resArray["TOKEN"] );
  } 


function CallShortcutExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL) 
    {
        //------------------------------------------------------------------------------------------------------------------------------------
        // Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation

        $nvpstr="&AMT=". $paymentAmount;
        $nvpstr = $nvpstr . "&PAYMENTACTION=" . $paymentType;
        $nvpstr = $nvpstr . "&BILLINGAGREEMENTDESCRIPTION=".urlencode("Test Recurring Payment($1 monthly)");
        $nvpstr = $nvpstr . "&BILLINGTYPE=RecurringPayments";
        $nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;
        $nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
        $nvpstr = $nvpstr . "&CURRENCYCODE=" . $currencyCodeType;

        $_SESSION["currencyCodeType"] = $currencyCodeType;    
        $_SESSION["PaymentType"] = $paymentType;

        //'--------------------------------------------------------------------------------------------------------------- 
        //' Make the API call to PayPal
        //' If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.  
        //' If an error occured, show the resulting errors
        //'---------------------------------------------------------------------------------------------------------------

        $resArray=hash_call("SetExpressCheckout", $nvpstr);
        $ack = strtoupper($resArray["ACK"]);
        if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
        {
            $token = urldecode($resArray["TOKEN"]);
            $_SESSION['TOKEN']=$token;
        }

        return $resArray;
    }

This function is for creating a recurring profile which is not called anywhere in the sample code.

function CreateRecurringPaymentsProfile()
    {
        //'--------------------------------------------------------------
        //' At this point, the buyer has completed authorizing the payment
        //' at PayPal.  The function will call PayPal to obtain the details
        //' of the authorization, incuding any shipping information of the
        //' buyer.  Remember, the authorization is not a completed transaction
        //' at this state - the buyer still needs an additional step to finalize
        //' the transaction
        //'--------------------------------------------------------------
        $token      = urlencode($_SESSION['TOKEN']);
        $email      = urlencode($_SESSION['email']);
        $shipToName     = urlencode($_SESSION['shipToName']);
        $shipToStreet       = urlencode($_SESSION['shipToStreet']);
        $shipToCity     = urlencode($_SESSION['shipToCity']);
        $shipToState        = urlencode($_SESSION['shipToState']);
        $shipToZip      = urlencode($_SESSION['shipToZip']);
        $shipToCountry  = urlencode($_SESSION['shipToCountry']);

        //'---------------------------------------------------------------------------
        //' Build a second API request to PayPal, using the token as the
        //'  ID to get the details on the payment authorization
        //'---------------------------------------------------------------------------
        $nvpstr="&TOKEN=".$token;
        #$nvpstr.="&EMAIL=".$email;
        $nvpstr.="&SHIPTONAME=".$shipToName;
        $nvpstr.="&SHIPTOSTREET=".$shipToStreet;
        $nvpstr.="&SHIPTOCITY=".$shipToCity;
        $nvpstr.="&SHIPTOSTATE=".$shipToState;
        $nvpstr.="&SHIPTOZIP=".$shipToZip;
        $nvpstr.="&SHIPTOCOUNTRY=".$shipToCountry;
        $nvpstr.="&PROFILESTARTDATE=".urlencode("2011-07-01T0:0:0");
        $nvpstr.="&DESC=".urlencode("Test Recurring Payment($1 monthly)");
        $nvpstr.="&BILLINGPERIOD=Month";
        $nvpstr.="&BILLINGFREQUENCY=5";
        $nvpstr.="&AMT=1";
        $nvpstr.="&CURRENCYCODE=USD";
        $nvpstr.="&IPADDRESS=" . $_SERVER['REMOTE_ADDR'];

        //'---------------------------------------------------------------------------
        //' Make the API call and store the results in an array.  
        //' If the call was a success, show the authorization details, and provide
        //'     an action to complete the payment.  
        //' If failed, show the error
        //'---------------------------------------------------------------------------
        $resArray=hash_call("CreateRecurringPaymentsProfile",$nvpstr);
        $ack = strtoupper($resArray["ACK"]);
        return $resArray;
    }

can I call this function to create the recurring profile in returnurl and pass the token id and payer id to this function.

1条回答
叛逆
2楼-- · 2019-09-08 17:03

Regardless of any library you're using, the flow should be SetExpressCheckout, GetExpressCheckoutDetails (optional), and then you can follow that up with either/or/both DoExpresscheckoutPayment and CreateRecurringPaymentsProfile.

If you're going to use CRPP you need to make sure SEC includes the billing agreement parameters, otherwise you'll end up with an invalid token error when you call CRPP. Here's an old sample of RAW API requests flow to make it work.

Then, if you're interested, you may want to take a look at my PHP class library for PayPal to make this easier on you. I know mine works. :)

查看更多
登录 后发表回答