当前位置: 首页 > 知识库问答 >
问题:

如何在提交其他表格之前不通过Stripe向信用卡收费(Laravel 4项目)

杭永安
2023-03-14

我正在尝试构建一个包含条带支付按钮的表单。它看起来是这样的(假设finish按钮在没有填写所有相关信息的情况下褪色):

现在我想做的是让用户填写上面的信息,然后点击支付1美元按钮。我想让用户填写他们的抄送信息(并且可以很容易地检查),但我不想让他们现在支付的条纹形式显示。我希望这只是为了保存他们的抄送信息,然后,一旦完成,就可以点击上面表格上的“完成”按钮提交付款和其他信息:

有什么办法可以做到这一点吗?

我正在使用Abodeo Laravel-Stripe包来处理付款:github.com/Abodeo/laravel-stripe

以下是一些示例代码:

视图(不包含所有输入,只是提供一个想法):

{{ Form::open(array('route' => 'fans.store')) }}

{{ Form::label('name', 'Name:') }}
{{ Form::text('name', null, array(
        'class'     => 'input',
        ));}}

{{ Form::label('email', 'Email:') }}
{{ Form::text('email', null, array(
        'class'     => 'input',
        ));}}

//STRIPE BUTTON
<div class="button_row">
{{ Form::button('Pay $1', array( 
        'id' => 'customButton',
        'class' => 'button',
        )); }}
</div>

//Submit
<div class="button_row">
{{Form::submit('Finish', ['class' => 'button'])}}
</div>

{{Form::close()}}

JS处理条纹:

<script>
  var handler = StripeCheckout.configure({
    key: '*************************',
    image: '/assets/images/1024icon.png',
    token: function(token) {
      // Use the token to create the charge with a server-side script.
      // You can access the token ID with `token.id`
    }
  });

  $('#customButton').on('click', function(e) {
    // Open Checkout with further options
    handler.open({
      name: '******',
      description: '**************',
      amount: 100
    });
    e.preventDefault();
  });

  // Close Checkout on page navigation
  $(window).on('popstate', function() {
    handler.close();
  });
</script>

服务器端:

目前,我的控制器中有两个函数,分别处理另一个表单输入和条带输入。我希望它能在一个函数中处理所有这些(当单击finish时)。

public function store()
        {

            $v = Fan::validate(Input::all());

            $full_name = Input::get('name');
            $name_pieces = explode(" ", $full_name);
            $first_name = $name_pieces[0]; 
            $last_name = $name_pieces[1];

            if ( $v->passes() ) {        

            $fan = new Fan;
            $fan->first_name = $first_name;
            $fan->last_name = $last_name;
            $fan->email = Input::get('email');
            $fan->save();


            return Redirect::to('/thisview);
            }
        }

        public function stripe_pay() {
            // Use the config for the stripe secret key
            Stripe::setApiKey(Config::get('stripe.stripe.secret'));

            // Get the credit card details submitted by the form
            $token = Input::get('stripeToken');

            // Create the charge on Stripe's servers - this will charge the user's card
            try {
                $charge = Stripe_Charge::create(array(
                  "amount" => 100, // amount in cents
                  "currency" => "usd",
                  "card"  => $token,
                  "description" => 'Charge for my product')
                );

            } catch(Stripe_CardError $e) {
                $e_json = $e->getJsonBody();
                $error = $e_json['error'];
                // The card has been declined
                // redirect back to checkout page
                return Redirect::to('/artists/'.$artist_id)
                    ->withInput()->with('stripe_errors',$error['message']);
            }
            // Maybe add an entry to your DB that the charge was successful, or at least Log the charge or errors
            // Stripe charge was successfull, continue by redirecting to a page with a thank you message
            return Redirect::to('thisview/success');

        }

共有1个答案

仲孙凡
2023-03-14

首先-你不只是使用Laravel收银员包的任何原因:http://laravel.com/docs/5.0/billing?

无论如何,你只需要更改你的store()函数,然后简单地保存你得到的条带标记$Token=Input::get('stripeToken') 进入某个会话。

然后,您可以尝试在稍后提交表单时收取该代币的费用。没有必要立即尝试充电。

 类似资料:
  • 问题内容: 有没有一种方法可以使用javascript和JQuery添加一些其他字段,这些字段将使用POST从HTTP表单发送? 我的意思是: 问题答案: 是的。您可以尝试使用一些隐藏的参数。

  • 问题内容: 我正在尝试通过ajax帖子提交多种表单,但是问题是服务器在帖子中返回了一个空数组。 这是我的JS中的代码: 在服务器端: 我究竟做错了什么?谢谢! 问题答案: 不,没有属性,其: 是标记中使用的属性。 样本输出 旁注:我认为更合适: 另一个例子

  • 问题内容: 我想使用JSoup将一些文本提交到此表单中。我将如何去做呢? 问题答案: 看一下jsoup.connect方法和Connection接口。 准备好要提交的文本后,可以将其作为表单提交发布到URL。 例如: 返回的对象将是帖子的结果页面。

  • 我有一个名为login.js的VUEX存储模块,如下所示 登录。vue代码 登录功能工作,令牌是第一次设置,但当我刷新浏览器的不见了。 在浏览器中,它显示如下 但是如果我通过开发工具提交,它会起作用,状态会变得持久。 类似性质的问题,但不回答这个问题。 vuex提交不提交到存储 Vue2 Vuex提交未提交(不带Vue devtools) 运行Vuex突变,但组件在vue开发工具中手动提交之前不会

  • 我按照给定的链接提交要保存在数据库中的表数据 http://viralpatel.net/blogs/spring-mvc-multi-row-submit-java-list/ 但是给定链接和我的实现之间的区别是链接的前端使用JSTL(JSP),而我使用Thymeleaf(超文本标记语言) 下面是正在使用的文件 HTML表单: 模型等级: 表格类: 控制器方法: 请让我知道我错过了什么。 更新1

  • 我正在构建一个移动Web应用程序,它从我构建的Symfony2应用程序中获取信息。用户必须提交一个表单才能查看信息,但是当我通过AJAX提交表单时,处理它的控制器看不到正在提交的表单。 移动应用程序是用Cordova构建的,因此表单来源于静态HTML表单。一旦通过AJAX提交,AJAX将返回所需的数据。然而,表单提交很好,这让AJAX发挥了神奇的作用,但是Symfony2没有看到表单被提交。我对