Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cardButton.addEventListener('click', function(ev) {
- ev.preventDefault();
- stripe.handleCardPayment(
- clientSecret, card, {
- payment_method_data: {
- billing_details: {name: cardholderName}
- }
- }
- ).then(function(result) {
- if (result.error) {
- $('.alert-danger').html('<span>'+ result.error +'</span>');
- $('.alert-danger').show();
- } else {
- // The payment has succeeded. Display a success message.
- fetch('{{ path('confirm_pay',{'id': id }) }}', {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ payment_method_id: result.paymentMethod, token: clientSecret , id: {{ id }} })
- }).then(function(result) {
- console.log(result);
- // Handle server response (see Step 3)
- result.json().then(function(json) {
- handleServerResponse(json);
- });
- });
- }
- });
- });
- /**
- * @Route("/confirm/{id}", name="confirm_pay", methods="POST")
- */
- public function confirmAction(Request $request)
- {
- $result = json_decode($this->paymentManager->confirmPaymentCard($request->get('id')), true);
- if($result['success'] == true)
- {
- $this->session->set('success-card', $result['message'] );
- $response = $this->forward('App\Controller\PaymentController::successAction', [
- ]);
- return $response;
- }else{
- return $this->render('facturation/pay.html.twig');
- }
- }
- /**
- * @Route("/success", name="success_pay", methods="GET")
- */
- public function successAction(Request $request)
- {
- return $this->render('facturation/success.html.twig', ['data'=> $this->session->get('success-card')]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement