Skip to content

Commit dc3a534

Browse files
test(apm): update APM example page to use "flow" to determine whether to call tokenization or authorization
1 parent f2ec756 commit dc3a534

2 files changed

Lines changed: 42 additions & 42 deletions

File tree

examples/apm/index.html

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
<select name="gateway" id="apm-gateway">
1313
<option value="">Select Gateway</option>
1414
</select>
15+
<select id="flow-type" name="flow_type">
16+
<option value="pay">Pay</option>
17+
<option value="pay-with-token">Pay with token</option>
18+
<option value="tokenize">Tokenize</option>
19+
<option value="buy-and-tokenize">Buy &amp; Tokenize</option>
20+
</select>
1521
<input type="text" id="invoice-id" name="invoice_id" placeholder="Invoice ID" />
1622
<input type="text" id="customer-id" name="customer_id" placeholder="Customer ID" style="display: none" />
1723
<input type="text" id="customer-token-id" name="customer_token_id" placeholder="Customer Token ID" style="display: none" />
@@ -67,12 +73,11 @@
6773
gatewayDict[option.value] = option.textContent.trim();
6874
});
6975

76+
const flowTypeEl = document.querySelector('#flow-type');
7077
const invoiceIdEl = document.querySelector('#invoice-id');
7178
const customerIdEl = document.querySelector('#customer-id');
7279
const customerTokenIdEl = document.querySelector('#customer-token-id');
7380

74-
let flow = 'authorization';
75-
7681
let previousId;
7782
let previousGateway;
7883

@@ -115,31 +120,18 @@
115120
return Object.keys(redirect).length ? { redirect } : {};
116121
}
117122

118-
gatewayEl.addEventListener('change', (e) => {
119-
const value = e.target.value;
120-
const gateway = gatewayDict[value];
123+
function syncInputVisibility() {
124+
const ft = flowTypeEl.value;
125+
invoiceIdEl.style.display =
126+
(ft === 'pay' || ft === 'pay-with-token' || ft === 'buy-and-tokenize') ? 'inline-block' : 'none';
127+
customerIdEl.style.display =
128+
(ft === 'tokenize' || ft === 'buy-and-tokenize') ? 'inline-block' : 'none';
129+
customerTokenIdEl.style.display =
130+
(ft === 'pay-with-token' || ft === 'tokenize' || ft === 'buy-and-tokenize') ? 'inline-block' : 'none';
131+
}
121132

122-
switch (gateway) {
123-
case 'Forage Authorization':
124-
flow = 'authorization';
125-
invoiceIdEl.style.display = 'inline-block';
126-
customerIdEl.style.display = 'none';
127-
customerTokenIdEl.style.display = 'inline-block';
128-
break;
129-
case 'Forage Tokenization':
130-
flow = 'tokenization';
131-
invoiceIdEl.style.display = 'none';
132-
customerIdEl.style.display = 'inline-block';
133-
customerTokenIdEl.style.display = 'inline-block';
134-
break;
135-
default:
136-
flow = 'authorization';
137-
invoiceIdEl.style.display = 'inline-block';
138-
customerIdEl.style.display = 'none';
139-
customerTokenIdEl.style.display = 'none';
140-
break;
141-
}
142-
})
133+
flowTypeEl.addEventListener('change', syncInputVisibility);
134+
syncInputVisibility();
143135

144136
document.querySelector('#initialise-apm').addEventListener('submit', (e) => {
145137
e.preventDefault()
@@ -150,7 +142,14 @@
150142

151143
let apm;
152144

153-
if (flow === 'authorization') {
145+
const flowType = flowTypeEl.value;
146+
const needsInvoice = flowType === 'pay' || flowType === 'pay-with-token' || flowType === 'buy-and-tokenize';
147+
const needsCustomer = flowType === 'tokenize' || flowType === 'buy-and-tokenize';
148+
const needsCustomToken = flowType === 'pay-with-token' || flowType === 'tokenize' || flowType === 'buy-and-tokenize';
149+
const useAuth = flowType !== 'tokenize';
150+
const useToken = flowType === 'tokenize';
151+
152+
if (needsInvoice) {
154153
if (!invoiceId) {
155154
alert('Please enter an invoice ID')
156155
return;
@@ -167,15 +166,27 @@
167166
}
168167

169168
if (previousId === invoiceId) {
170-
const result = confirm("You're using a invoice id that has already been used. Are you sure you want to use it again?")
169+
const result = confirm("You're using an invoice id that has already been used. Are you sure you want to use it again?")
171170
if (!result) {
172171
return
173172
}
174173
}
175174

176-
177175
previousId = invoiceId;
178176
previousGateway = gatewayConfigurationId;
177+
}
178+
179+
if (needsCustomer && !customerId) {
180+
alert('Please enter a customer ID')
181+
return
182+
}
183+
184+
if (needsCustomToken && !customerTokenId) {
185+
alert('Please enter a customer token ID')
186+
return
187+
}
188+
189+
if (useAuth) {
179190
apm = client.apm.authorization(el, {
180191
gatewayConfigurationId,
181192
invoiceId,
@@ -189,18 +200,7 @@
189200
},
190201
...buildRedirectOptions(),
191202
})
192-
}
193-
194-
if (flow === 'tokenization') {
195-
if (!customerId) {
196-
alert('Please enter a customer ID')
197-
return
198-
}
199-
if (!customerTokenId) {
200-
alert('Please enter a customer token ID')
201-
return
202-
}
203-
203+
} else if (useToken) {
204204
apm = client.apm.tokenization(el, {
205205
gatewayConfigurationId,
206206
customerId,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "processout.js",
3-
"version": "1.9.0",
3+
"version": "1.9.1",
44
"description": "ProcessOut.js is a JavaScript library for ProcessOut's payment processing API.",
55
"scripts": {
66
"build:processout": "tsc -p src/processout && uglifyjs --compress --keep-fnames --ie8 dist/processout.js -o dist/processout.js",

0 commit comments

Comments
 (0)