如何在paypal重复的配置文件快速结账时CallShortcutExpressCheckout后调用CreateRecurringPaymentsProfile

时间:2013-12-02 21:19:15

标签: paypal recurring-billing

我已经在我的网站上下载并实现了这个paypal集成库。 https://github.com/hrendoh/PayPal-Express-Checkout-example

不会创建重复的配置文件。

快速结账的功能调用是

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

此函数用于创建重复的配置文件,该配置文件不会在示例代码中的任何位置调用。

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

我可以调用此函数在returnurl中创建重复的配置文件,并将令牌I​​D和付款人ID传递给此函数。

1 个答案:

答案 0 :(得分:2)

无论您使用的是哪个库,流程都应为SetExpressCheckoutGetExpressCheckoutDetails(可选),然后您可以使用/或/ DoExpresscheckoutPaymentCreateRecurringPaymentsProfile

如果您要使用CRPP,您需要确保SEC包含结算协议参数,否则在您致电CRPP时最终会出现无效的令牌错误。 Here's an old sample RAW API请求流程使其正常工作。

然后,如果您感兴趣,可能需要查看我的PHP class library for PayPal,以便让您更轻松。我知道我的作品。 :)