【问题标题】:How to integrate paypal in Zend Framework 1.12?如何在 Zend Framework 1.12 中集成 paypal?
【发布时间】:2013-02-14 11:00:02
【问题描述】:

我知道你可能会问我为什么不先尝试 google 解决方案,现在我可以说我已经用 google 搜索过了,不幸的是它提供了太多的解决方案和不同的方法。

我的情况是这样的,我想让那些客户能够每年订阅我的服务。

来自this link,他们提出了太多的解决方案,我不知道哪一个适合我的情况。当然,我想使用免费服务(直接借记需要月费)

也就是说,我希望每年在我的客户订阅的服务到期时将交易#存储到我的数据库中,并自动向客户和我公司的电子邮件发送确认电子邮件。

总之,

  1. 哪种方式适合我的情况。
  2. 在这种情况下是否需要 cron 作业?还是只需要使用 paypal 提供的定期付款?
  3. 是否有任何链接或示例(即沙盒中的编码实现)

提前致谢。

【问题讨论】:

标签: php zend-framework paypal sandbox


【解决方案1】:

您可以使用 PayPal Payments Pro 和 Direct Payment API 来处理初始信用卡交易。然后您可以将交易存储在您的系统中,并将您的系统设置为运行 cron 作业并执行参考交易 API 调用以再次向买家收费。这将为您提供设置定期付款配置文件的效果,而无需通过 PayPal 实际使用该服务。

但是,如果您希望减少编码和设置系统以执行 cron 作业等,那么您可以注册 PayPal 的定期付款/定期计费服务,这样您只需调用 API 即可PayPal 设置个人资料。然后 PayPal 会在您的买家应该付款时向他们收费。

【讨论】:

    【解决方案2】:

    您好,我为 ZF 编写了代码

    public function processPaymentAction()
    {
        $methodName = 'CreateRecurringPaymentsProfile';
        // from nvpHeader function
        $API_Endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
        $version = '65.2';
    
        // But you can use here your own Sandbox API credentials of Business account
        // and you can get through Payapl Sandbox API Credentials Link on Left.
    
        $API_UserName = 'platfo_1255077030_biz_api1.gmail.com';
        $API_Password = '1255077037';
        $API_Signature = 'Abg0gYcQyxQvnf2HDJkKtA-p6pqhA1k-KTYE0Gcy1diujFio4io5Vqjf';
        $subject = '';
        global $nvp_Header, $AUTH_token, $AUTH_signature, $AUTH_timestamp;
        $nvpHeaderStr = "";
    
        //pr($this->data);die;
        //$this->data['User']['paymentType']
        $paymentType = urlencode('Sale');
        $firstName = urlencode("Jaskaran");
        $lastName = urlencode("Singh");
        $creditCardType = urlencode("Visa");
        $creditCardNumber = urlencode("4798720058660243");
        $expDateMonth =urlencode(11);
    
        // Month must be padded with leading zero
        $padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);
    
        $expDateYear = urlencode(2015);
        $cvv2Number = urlencode(962);
        $address1 = urlencode("1 Main St");
        $address2 = urlencode("");
        $city = urlencode("San Jose");
        $state = urlencode("CA");
        $zip = urlencode(95131);
        $amount = urlencode(1.00);
    
    //  $init_amount = urlencode($this->data['User']['pack_price']);
    
        $currencyCode="USD";
    
        $profileDesc = urlencode("Welcome to the world of shopping where you get everything");
        $billingPeriod = urlencode("Week");
        $billingFrequency = urlencode(4);
        $totalBillingCycles = urlencode(0);
    
        ################# Commented as we need to define through Admin ##############
    
        $profileStartDateDay = 10;
        // Day must be padded with leading zero
        $padprofileStartDateDay = str_pad($profileStartDateDay, 2, '0', STR_PAD_LEFT);
    
        $profileStartDateMonth = 02;
        // Month must be padded with leading zero
        $padprofileStartDateMonth = str_pad($profileStartDateMonth, 2, '0', STR_PAD_LEFT);
    
        $profileStartDateYear = 2015;
    
        $profileStartDate = urlencode($profileStartDateYear . '-' . $padprofileStartDateMonth . '-' . $padprofileStartDateDay . 'T00:00:00Z');
    
        //string from nvpHeader
        $nvpHeaderStr = "&PWD=".urlencode($API_Password)."&USER=".urlencode($API_UserName)."&SIGNATURE=".urlencode($API_Signature);
    
        $nvpstr="&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber&EXPDATE=". $padDateMonth.$expDateYear."&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName&STREET=$address1&CITY=$city&STATE=$state".
        "&ZIP=$zip&COUNTRYCODE=US&CURRENCYCODE=$currencyCode&PROFILESTARTDATE=$profileStartDate&DESC=$profileDesc&BILLINGPERIOD=$billingPeriod&BILLINGFREQUENCY=$billingFrequency&TOTALBILLINGCYCLES=$totalBillingCycles";
    
        $nvpstr = $nvpHeaderStr.$nvpstr;
        //check if version is included in $nvpStr else include the version.
        if(strlen(str_replace('VERSION=','', strtoupper($nvpstr))) == strlen($nvpstr)) 
        {
            $nvpstr = "&VERSION=" . urlencode($version) . $nvpstr;
        }
        $nvpreq="METHOD=".urlencode($methodName).$nvpstr;
    
    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$API_Endpoint);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_POST, 1);
    
        //$nvpreq=”METHOD=”.urlencode($methodName).$nvpStr;
    
        //setting the nvpreq as POST FIELD to curl
        curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);
    
        //getting response from server
        $response = curl_exec($ch);
    
        //convrting NVPResponse to an Associative Array
        $nvpResArray=$this->deformatNVP($response);
        $nvpReqArray=$this->deformatNVP($nvpreq);
    
    
        if (curl_errno($ch)) 
        {
            echo "cURL Error";
            die;
            // moving to display page to display curl errors
            $_SESSION['curl_error_no']=curl_errno($ch) ;
            $_SESSION['curl_error_msg']=curl_error($ch);
            //$location = "APIError.php";
            //header("Location: $location");
        } 
        else 
        {
            //closing the curl
            curl_close($ch);
        }
    
        #### Checking error ###
        if(!empty($nvpResArray))
        {
            if($nvpResArray['ACK'] == 'Failure')
            {
                echo "ERROR : ". $errmsg = $nvpResArray["L_LONGMESSAGE0"];
                echo "<pre>";
                print_r($nvpResArray);
                die;
            }
        }
    
        // Print this array you will get some necessary info
        ################ Starting data insert##################
    
        if($nvpResArray['ACK'] == 'Success')
        {
            echo 'Success';
            print_r($nvpResArray);
            die;
            // save data into tables for Recurring Profile
        }
    
    
    
    }
    
    ############### Function deformatNVP #########
    /** This function will take NVPString and convert it to an Associative Array and it will decode the response.
     * It is usefull to search for a particular key and displaying arrays.
     * @nvpstr is NVPString.
     * @nvpArray is Associative Array.
     */
    function deformatNVP ($nvpstr)
    {
        $intial = 0;
        $nvpArray = array();
        while (strlen($nvpstr)) {
            //postion of Key
            $keypos = strpos($nvpstr, '=');
            //position of value
            $valuepos = strpos($nvpstr, '&') ? strpos($nvpstr, '&') : strlen(
            $nvpstr);
            /*getting the Key and Value values and storing in a Associative Array*/
            $keyval = substr($nvpstr, $intial, $keypos);
            $valval = substr($nvpstr, $keypos + 1, $valuepos - $keypos - 1);
            //decoding the respose
            $nvpArray[urldecode($keyval)] = urldecode($valval);
            $nvpstr = substr($nvpstr, $valuepos + 1, strlen($nvpstr));
        }
        return $nvpArray;
    }
    function formAutorization ($auth_token, $auth_signature, $auth_timestamp)
    {
        $authString = "token=" . $auth_token . ",signature=" . $auth_signature .
         ",timestamp=" . $auth_timestamp;
        return $authString;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多