如何用symfony 4解决“条带必须提供来源或客户”的问题

时间:2019-02-27 16:57:47

标签: symfony stripe-payments symfony4

我在Stripe和Symfony 4中遇到此问题:必须提供来源或客户。在提交我的付款请求之后。

我绝对不知道如何解决此问题。

这是我的代码:

视图:

<script                       
 src="https://checkout.stripe.com/checkout.js"
 class="stripe-button"
 data-key="pk_test_xxxxxxxxxxxxxxxxxxxxxxxx"
 data-amount="{{ app.request.request.get('hiddenPrice') * 100 }}"
 data-name="stripe.com"
 data-description="Widget"
 data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
 data-locale="auto"
 data-currency="eur">
</script>

我的控制器:

\Stripe\Stripe::setApiKey("sk_test_xxxxxxxxxxxxxxxxxxxxxxxx");


        // Get the credit card details submitted by the form

        $token = $request->request->get('stripeToken');


        // Create a charge: this will charge the user's card
        try {
            $charge = \Stripe\Charge::create(array(
                "amount" => 1000, // Amount in cents
                "currency" => "eur",
                "source" => $token,
                "description" => "Paiement Stripe - OpenClassrooms Exemple"
            ));
            $this->addFlash("success","Bravo ça marche !");
            return $this->redirectToRoute("emails");
        } catch(\Stripe\Error\Card $e) {

            $this->addFlash("error","Snif ça marche pas :(");
            return $this->redirectToRoute("payment");
            // The card has been declined
        }

我尝试遵循许多教程,但是我失败了。

0 个答案:

没有答案