Home » Php » WordPress Stripe Connect Issue

WordPress Stripe Connect Issue

Posted by: admin June 30, 2018 Leave a comment

Questions:

I have integrated Stripe connect using composer and get all files with vendor and autoload file with stripe folder with in folder and its working fine for core php on payment done payment details get save in sandbox account by hitting charge api and token api but same thing is not working while integrating it in wordpress site only token api is working actually iam using button type submit for payment form and providing action like url and then sucess page post-name and it gives error page not found if i hit that sucess page again it will execute error part. In core php i am passing only form action like sucess.php and and in sucess page including stripe vendor/autoad as require then stripe composer file its working properly.

<form action="<?php echo site_url();?>/index.php/stripe-sucess" method="POST" id="paymentFrm">
    <p>
        <label>Name</label>
        <input type="text" name="name" size="50" />
    </p>
    <p>
        <label>Email</label>
        <input type="text" name="email" size="50" />
    </p>
    <p>
        <label>Card Number</label>
        <input type="text" name="card_num" size="20" autocomplete="off" class="card-number" />
    </p>
    <p>
        <label>CVC</label>
        <input type="text" name="cvc" size="4" autocomplete="off" class="card-cvc" />
    </p>
    <p>
        <label>Expiration (MM/YYYY)</label>
        <input type="text" name="exp_month" size="2" class="card-expiry-month"/>
        <span> / </span>
        <input type="text" name="exp_year" size="4" class="card-expiry-year"/>
    </p>

<button type="submit" id="payBtn">Submit Payment</button>

</form>
<script type="text/javascript">
//set your publishable key
Stripe.setPublishableKey('pk_test_uFOdE1YPIXhbssFt1FwH9RGQ');

//callback to handle the response from stripe
function stripeResponseHandler(status, response) {
    if (response.error) {
        //enable the submit button
        $('#payBtn').removeAttr("disabled");
        //display the errors on the form
        $(".payment-errors").html(response.error.message);
    } else {
        var form$ = $("#paymentFrm");
        //get token id
        var token = response['id'];
       // alert(token);
        //insert the token into the form
        form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
        //submit form to the server
    form$.get(0).submit();
    }
}
$(document).ready(function() {
    //on form submit
    $("#paymentFrm").submit(function(event) {
        //disable the submit button to prevent repeated clicks
        $('#payBtn').attr("disabled", "disabled");

        //create single-use token to charge the user
        Stripe.createToken({
            number: $('.card-number').val(),
            cvc: $('.card-cvc').val(),
            exp_month: $('.card-expiry-month').val(),
            exp_year: $('.card-expiry-year').val()
        }, stripeResponseHandler);

        //submit from callback
        return false;
    });
});
paymentRequest.on('token', function(ev) {
  // Send the token to your server to charge it!
  fetch('/charges', {
    method: 'POST',
    body: JSON.stringify({token: ev.token.id}),
    headers: {'content-type': 'application/json'},
  })
  .then(function(response) {
    if (response.ok) {
      // Report to the browser that the payment was successful, prompting
      // it to close the browser payment interface.
      ev.complete('success');
    } else {
      // Report to the browser that the payment failed, prompting it to
      // re-show the payment interface, or show an error message and close
      // the payment interface.

      ev.complete('fail');
    }
  });
});
</script>
Answers: