javascript - Stripe API Status 200 OK No Event Created -
i utilizing stripe api test key. have payment form posting stripe api endpoint, no event being created. when check stripe event/logs able see 200 - ok success message under logs tab submitted test payment, events tab remains empty. can't seem figure out. code below.
here php processing payment:
function wpay_stripe_process_payment() { if(isset($_post['action']) && $_post['action'] == 'stripe' && wp_verify_nonce($_post['stripe_nonce'], 'stripe-nonce')) { global $stripe_options; // load stripe libraries require_once(stripe_base_dir . '/lib/stripe.php'); // retrieve token generated stripe.js $token = $_post['stripetoken']; // check if using test mode if(isset($stripe_options['test_mode']) && $stripe_options['test_mode']) { $secret_key = $stripe_options['test_secret_key']; } else { $secret_key = $stripe_options['live_secret_key']; } // attempt charge customer's card try { stripe::setapikey($secret_key); $charge = stripe_charge::create(array( 'amount' => 1000, // $10 'currency' => 'usd', 'card' => $token ) ); // redirect on successful payment $redirect = add_query_arg('payment', 'paid', $_post['redirect']); } catch (exception $e) { // redirect on failed payment $redirect = add_query_arg('payment', 'failed', $_post['redirect']); } // redirect our previous page added query variable wp_redirect($redirect); exit; } } add_action('wpay_stripe_process_payment');
here js sending payment info:
stripe.setpublishablekey(stripe_vars.publishable_key); function striperesponsehandler(status, response) { if (response.error) { // show errors returned stripe jquery(".payment-errors").html(response.error.message); // re-enable submit button jquery('#stripe-submit').attr("disabled", false); } else { var form$ = jquery("#stripe-payment-form"); // token contains id, last4, , card type var token = response['id']; // insert token form gets submitted server form$.append("<input type='hidden' name='stripetoken' value='" + token + "'/>"); // , submit form$.get(0).submit(); } } jquery(document).ready(function($) { $("#stripe-payment-form").submit(function(event) { // disable submit button prevent repeated clicks $('#stripe-submit').attr("disabled", "disabled"); // send card details stripe stripe.createtoken({ number: $('.card-number').val(), cvc: $('.card-cvc').val(), exp_month: $('.card-expiry-month').val(), exp_year: $('.card-expiry-year').val() }, striperesponsehandler); // prevent form submitting default action return false; }); });
json response:
{ "id": "tok_1b12dqg6oqhg3oednlzlfory", "object": "token", "card": { "id": "card_1b12dqg6oqhg3oediqa4fice", "object": "card", "address_city": null, "address_country": null, "address_line1": null, "address_line1_check": null, "address_line2": null, "address_state": null, "address_zip": null, "address_zip_check": null, "brand": "visa", "country": "us", "cvc_check": "unchecked", "dynamic_last4": null, "exp_month": 4, "exp_year": 2018, "funding": "credit", "last4": "4242", "metadata": { }, "name": null, "tokenization_method": null }, "client_ip": "187.232.128.105", "created": 1505177536, "livemode": false, "type": "card", "used": false }
your stripe token @ response.id
, not response['id']
:
// token contains id, last4, , card type var token = response.id;
the response json object, have traverse object other js object.
Comments
Post a Comment