mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Import StripeJS mock from fake_stripe gem
This is the original from https://github.com/thoughtbot/fake_stripe/blob/v0.3.0/lib/fake_stripe/assets/v3.js
This commit is contained in:
34
spec/support/fixtures/stripejs-mock.js
Normal file
34
spec/support/fixtures/stripejs-mock.js
Normal file
@@ -0,0 +1,34 @@
|
||||
class Element {
|
||||
mount(el) {
|
||||
if (typeof el === "string") {
|
||||
el = document.querySelector(el);
|
||||
}
|
||||
|
||||
el.innerHTML = `
|
||||
<input id="stripe-cardnumber" placeholder="cardnumber" size="16" type="text">
|
||||
<input placeholder="exp-date" size="6" type="text">
|
||||
<input placeholder="cvc" size="3" type="text">
|
||||
<input placeholder="postal" size="6" type="text">
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
window.Stripe = () => {
|
||||
const fetchLastFour = () => {
|
||||
return document.getElementById("stripe-cardnumber").value.substr(-4, 4);
|
||||
};
|
||||
|
||||
return {
|
||||
elements: () => {
|
||||
return {
|
||||
create: (type, options) => new Element()
|
||||
};
|
||||
},
|
||||
|
||||
createToken: card => {
|
||||
return new Promise(resolve => {
|
||||
resolve({ token: { id: "tok_123", card: { last4: fetchLastFour() } } });
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user