The repo to build up a demo flow how to use the Stripe API for integration.
https://stripe.com/docs/js
https://stripe.com/docs/sources
https://stripe.com/docs/api/sources/create
https://stripe.com/docs/webhooks
https://stripe.com/docs/testing#cards
We need for test under HTTPS and receive the event from Webhook
https://ngrok.com/
$ git clone https://github.com/oliguo/PHP-Stripe.git
$ composer install
/**
* Get the 'STRIPE_SECRET_KEY' and 'STRIPE_PUBLISHABLE_KEY' from
* https://dashboard.stripe.com/test/apikeys After you login
*
* Get the 'STRIPE_WEBHOOK_SECRET' from
* https://dashboard.stripe.com/test/webhooks After you login
*/
define("STRIPE_SECRET_KEY","sk_test_xxx");
define("STRIPE_PUBLISHABLE_KEY","pk_test_xxx");
define("STRIPE_WEBHOOK_SECRET","whsec_xxx");
$ php -S localhost:5000
$ ngrok http 5000
https://dashboard.stripe.com/test/webhooks
http://localhost:5000/web/one-input-card.php
http://localhost:5000/web/multi-input-card.php
http://localhost:5000/web/others.php
/**
* If you would like to handle card, e.g.Limit only visa
* https://stripe.com/docs/js/element/events/on_change?type=cardElement
*/
card.on('change', function (event) {
if (event.error) {
// show validation to customer
}
var displayError = document.getElementById('card-errors');
if (event.brand === 'visa') {
// to do the logic
displayError.textContent = '';
} else {
displayError.textContent = 'only visa';
}
});