简体   繁体   English

Braintree Paypal 在 codeigniter 中不起作用

[英]braintree paypal is not working in codeigniter

I want to integrate Braintree paypal in my codeigniter website.i load braintree files and credentials from server in my controllers constructor and put other code in a method but it always giving the error Unknown or expired payment_method_nonce.Below is method我想在我的 codeigniter 网站中集成 Braintree paypal。我在我的控制器构造函数中从服务器加载 Braintree 文件和凭据,并将其他代码放入一个方法中,但它总是给出错误 Unknown or expired payment_method_nonce.Below 是方法

public function braintree(){
    if($this->session->userdata('user_id') != '' && $this->session->userdata('user_id') != 'user'){
        $user_id        = $this->input->post('user_id');
        $amount         = $this->input->post('amount');
        $inscription_id = $this->input->post('inscription_id');

        $user_details = $this->db->get_where('spm_users',array('id'=>$user_id))->row_array();
        if(!empty($user_details->braintree_customer_id)){
            $CustomerId =  (string)$user_details->braintree_customer_id;
        }else{
            $result = Braintree_Customer::create([
                        'firstName' => $user_details->name,
                        'lastName' => $user_details->surname,
                        'email' => $user_details->email,
                        'phone' => $user_details->telephone,
                    ]);
                $CustomerId = (string)$result->customer->id;
                $this->db->where("id",$user_id);
                $this->db->update("spm_users", array('braintree_customer_id'=>$CustomerId));
        }
        $clientToken = Braintree_ClientToken::generate([
                        "customerId" => $CustomerId
                    ]);
        $card_id ='';            
        $clientToken_new = Braintree_ClientToken::generate();
        $result1 = Braintree_Transaction::sale([
                      'amount' => $amount,
                      'paymentMethodNonce' => $clientToken_new,
                      'options' => [
                        'submitForSettlement' => True
                      ]
                    ]);
        if($result1->success == true){ 
            $updateArr = array(
                'amount'=>$result1->transaction->amount,
                'balance_transaction'=>$result1->transaction->id,
                'inscription_status'=>2,
                'status'=>1,
                'data'=>json_encode($result1),
                'payment_method'        => 'Braintree',
                'payment_date'=>date('Y-m-d H:i:s')
                );
                $this->db->where("id",$inscription_id);
                $this->_db->update("spm_inscription", $updateArr);
                $this->session->set_flashdata('msg','Inscription Payment Success');
                redirect('frontend/paypalpayment/'.$inscription_id);
        }else{
            $this->session->set_flashdata('msg','Payment failed');
            redirect('frontend/paypalpayment/'.$inscription_id);
        }    
    }else{
        redirect('frontend');
    } 
}

and here is my constructor这是我的构造函数

public function __construct() {
    parent::__construct();
    require_once '/home/public_html/mysite/braintree/Braintree.php';
    Braintree_Configuration::environment('sandbox');
    Braintree_Configuration::merchantId('zxxxxxxxxxxxxxxd');
    Braintree_Configuration::publicKey('7xxxxxxxxxxxxxxx7');
    Braintree_Configuration::privateKey('1xxxxxxxxxxxxxxxxxxxxxx8');
}

i tried google but no luck.please help and thanks in advance.我试过谷歌,但没有运气。请提前帮助和感谢。

Full disclosure: I work at Braintree.完全披露:我在布伦特里工作。 If you have any further questions, feel free to contact support .如果您有任何其他问题,请随时联系支持

From the documentation on Transaction:sale() :Transaction:sale()文档

To create a transaction, you must include an amount and either a paymentMethodNonce or a paymentMethodToken.要创建交易,您必须包含一个金额和一个 paymentMethodNonce 或一个 paymentMethodToken。

The parameter that you're passing in your paymentMethodNonce parameter is not a payment method nonce .您在paymentMethodNonce参数中传递的参数不是付款方式 nonce Instead, you're passing it a client token , which is causing it to fail.相反,您正在向它传递一个客户端令牌,这导致它失败。 These items are similarly-named, but have very different purposes.这些物品名称相似,但用途却截然不同。

  • Client token : contains configuration information about your gateway account.客户端令牌:包含有关您的网关帐户的配置信息。 The client-side SDKs use them to set up their own configuration correctly and work seamlessly with your server, and they should not be passed to transaction sale calls. 客户端 SDK使用它们来正确设置自己的配置并与您的服务器无缝协作,并且不应将它们传递给交易销售调用。
  • Payment method nonce : a reference to a set of tokenized payment method information, such as a credit card number and expiration date. Payment method nonce :对一组标记化的支付方式信息的引用,例如信用卡号和到期日期。 These are generally produced by the tokenize calls in the client-side SDKs after a user enters credit card information.这些通常由用户输入信用卡信息后客户端 SDK 中的标记化调用生成
  • Payment method token : a reference to a payment method that you've saved in your Braintree account.付款方式令牌:对您保存在 Braintree 帐户中的付款方式的引用。

To create a transaction properly in your code, you'll have to either reference a payment method that you've saved in your vault (by using a payment method token), or reference a set of newly-tokenized payment method information that a customer submitted on your website (by using a payment method nonce).要在您的代码中正确创建交易,您必须参考您保存在保险库中的付款方式(通过使用付款方式令牌),或参考客户提供的一组新令牌化的付款方式信息在您的网站上提交(通过使用付款方式 nonce)。 For example, if you were to save the customers' payment method tokens in your database, you might run something like this:例如,如果您要将客户的付款方式令牌保存在您的数据库中,您可能会运行如下代码:

    if (!empty($user_details->braintree_customer_id)) {
        $CustomerId = (string) $user_details->braintree_customer_id;
        $CustomerSavedPaymentMethod = (string) $user_details->payment_method_token;
    } else {
        ...
    }

    $result1 = Braintree_Transaction::sale([
        'amount' => $amount,
        'paymentMethodToken' => $CustomerSavedPaymentMethod,
        'options' => [
            'submitForSettlement' => True
        ]
    ]);

If you need some additional resources to create a payment method nonce and pass it back to your server, you can reference our full PHP integration example .如果您需要一些额外的资源来创建支付方式随机数并将其传回您的服务器,您可以参考我们完整的 PHP 集成示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM