代码之家  ›  专栏  ›  技术社区  ›  Divine Izere

从旧条带检出迁移到codeigniter中的新版本

  •  0
  • Divine Izere  · 技术社区  · 4 年前

    我正在做一个项目,它将作为一个市场网站。我已经有了条纹库作为初始付款方式,可以从网站上接收客户的付款,但看起来旧版本的条纹已经升级,我想采用新版本。

    public function stripe_payment_post()
    {
        require_once(APPPATH . 'third_party/stripe/vendor/autoload.php');
        try {
            $token = $this->input->post('payment_id', true);
            $email = $this->input->post('email', true);
            $payment_amount = $this->input->post('payment_amount', true);
            $currency = $this->input->post('currency', true);
            //Init stripe
            $stripe = array(
                "secret_key" => $this->payment_settings->stripe_secret_key,
                "publishable_key" => $this->payment_settings->stripe_publishable_key,
            );
            
            \Stripe\Stripe::setApiKey($stripe['secret_key']);
            //customer
            $customer = \Stripe\Customer::create(array(
                'email' => $email,
                'source' => $token
            ));
            //charges
            $charge = \Stripe\Charge::create(array(
                'customer' => $customer->id,
                'amount' => $payment_amount,
                'currency' => $currency,
                'description' => trans("stripe_checkout")
            ));
    
            //add to database
            $data_transaction = array(
                'payment_method' => "Stripe",
                'payment_id' => $token,
                'currency' => $currency,
                'payment_amount' => get_price($payment_amount, 'decimal'),
                'payment_status' => $this->input->post('payment_status', true),
            );
    
        } catch (\Stripe\Error\Base $e) {
            $this->session->set_flashdata('error', $e->getMessage());
            $data = array(
                'status' => 0,
                'redirect' => generate_url("cart", "payment")
            );
            echo json_encode($data);
        } catch (Exception $e) {
            $this->session->set_flashdata('error', $e->getMessage());
            $data = array(
                'status' => 0,
                'redirect' => generate_url("cart", "payment")
            );
            echo json_encode($data);
        }
    }
    

    //这是客户端

    <script src="https://checkout.stripe.com/v2/checkout.js"></script>
    <script>
        var handler = StripeCheckout.configure({
            key: '<?php echo $this->payment_settings->stripe_publishable_key; ?>',
            image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
            locale: 'auto',
            currency: '<?php echo $currency; ?>',
            token: function (token) {
                var data = {
                    'payment_id': token.id,
                    'email': token.email,
                    'currency': '<?php echo $currency; ?>',
                    'payment_amount': '<?php echo $total_amount; ?>',
                    'payment_status': 'success',
                   
                    'sys_lang_id': sys_lang_id
                };
                data[csfr_token_name] = $.cookie(csfr_cookie_name);
                $.ajax({
                    type: "POST",
                    url: base_url + "stripe-payment-post",
                    data: data,
                    success: function (response) {
                        var obj = JSON.parse(response);
                        if (obj.result == 1) {
                            window.location.href = obj.redirect;
                        } else {
                            location.reload();
                        }
                    }
                });
            }
        });
        document.getElementById('btn_stripe_checkout').addEventListener('click', function (e) {
            handler.open({
                name: '<?php echo html_escape($this->general_settings->application_name); ?>',
                description: '<?php echo trans("stripe_checkout"); ?>',
                amount: '<?php echo $total_amount; ?>'
            });
            e.preventDefault();
        });
        // Close Checkout on page navigation:
        window.addEventListener('popstate', function () {
            handler.close();
        });
    </script>
    
    0 回复  |  直到 4 年前
        1
  •  0
  •   floatingLomas    4 年前

    您可以在此处找到描述此迁移的文档: https://stripe.com/docs/payments/checkout/migration