From 49bd9bd778da6a9b7298f7eebc00571a87c2ace4 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 18 Sep 2020 20:17:07 +0100 Subject: [PATCH] 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 --- spec/support/fixtures/stripejs-mock.js | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 spec/support/fixtures/stripejs-mock.js diff --git a/spec/support/fixtures/stripejs-mock.js b/spec/support/fixtures/stripejs-mock.js new file mode 100644 index 0000000000..e53f0e1b11 --- /dev/null +++ b/spec/support/fixtures/stripejs-mock.js @@ -0,0 +1,34 @@ +class Element { + mount(el) { + if (typeof el === "string") { + el = document.querySelector(el); + } + + el.innerHTML = ` + + + + + `; + } +} + +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() } } }); + }); + } + }; +};