提交条纹表单时“无法向没有活动卡的客户收费”

时间:2015-03-22 17:41:46

标签: php symfony stripe-payments

我试图让Stripe使用Symfony2项目。当我提交表单时,我收到了错误

  

无法向没有有效卡的客户收费

我不知道如何解决它... :) 我的控制器

<?php

namespace L3O1\ProjetBundle\Controller;

use L3O1\ProjetBundle\Entity\Payment;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\Model\UserInterface;

class PaymentController extends Controller {

    public function chargeAction(Request $request, $id) {
        $token  = $request->request->get('stripeToken');
        $email  = $request->request->get('stripeEmail');
        $amount = $request->request->get('amount');

        $em = $this->getDoctrine()->getManager();
        $projet = $em->getRepository('L3O1ProjetBundle:Projet')->find($id);

        $projet->setSommeDepart($projet->getSommeDepart()+$amount);
        $em->persist($projet);

        if($this->getUser() != null) {
            $payment = new Payment();
            $payment->setUserId($this->getId());
            $payment->setProjetId($projet->getId());
            $payment->setAmount($amount);
            $payment->setDate(new \Datetime());
            $em->persist($payment);
        }

        $em->flush();

        \Stripe\Stripe::setApiKey('mykey');

        $customer = \Stripe\Customer::create(array(
            'email' => $email,
            'source' => $token
        ));

        $charge = \Stripe\Charge::create(array(
            //amount in cent
            'amount'   => $amount*100,
            'currency' => 'eur',
            'customer' => $customer->id,
        ));

        return $this->render('L3O1ProjetBundle:Payments:charge.html.twig');
    }
}

我的表格

{# Stripe payment #}
            <script src="https://checkout.stripe.com/checkout.js"></script>
            <form id="chargeForm" methode="POST" action="{{ path('l3o1_projet_charge', { 'id': app.request.get('id') }) }}">
                <input type="number" name="amount" id="custom-donation" placeholder="Enter an amount" min="1.00" step "10.00"/>
                <input type="hidden" name="stripeToken" id="stripeToken" value="">
                <input type="hidden" name ="stripeEmail" id="stripeEmail" value="">
                <button id="customButton" class="btn btn-lg"> Back this project </button>

                <script>
                    var handler = StripeCheckout.configure({
                        key:'mykey',
                        //image
                        token: function(token, args) {
                            document.getElementById("stripeToken").value = token.id;
                            document.getElementById("stripeEmail").value = token.email;
                            document.getElementById("chargeForm").submit();
                        }
                    })

                    document.getElementById('customButton').addEventListener('click', function(e) {
                        handler.open({
                            name:        '{{ projet.titre }}',
                            description: '{{ projet.shortdesc }}',
                            amount:      document.getElementById('custom-donation').value*100,
                            currency:    'eur',
                        });
                        e.preventDefault();
                    });
                    </script>

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

好的,所以我很累。我的错误很简单,我写了#34; methode =&#34; POST&#34;&#34;而不是&#34;方法=&#34; POST&#34;&#34; ...我的控制器无法获取URL中的内容,因为它无法找到任何POST表单方法。< / p>