Skip to content

Commit f0fa048

Browse files
Merge pull request #79 from PaystackOSS/inlinejs
Feat: Add InlineJS snippets
2 parents b403577 + 43dce0a commit f0fa048

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+563
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const js = `onCancel: () => {
2+
console.log("User cancelled")
3+
}`
4+
5+
export {js}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const js = `onElementsMount: (elements) =>{ // { applePay: true } or null
2+
if (elements) {
3+
console.log(`Successfully mounted elements: ${JSON.stringify(elements)}`);
4+
} else {
5+
console.log('Could not load elements');
6+
}
7+
}`
8+
9+
export {js}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const js = `onError: (error) => {
2+
console.log(`Error: ${error.message}`);
3+
}`
4+
5+
export {js}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const js = `onLoad: (response) => {
2+
// Transaction has loaded
3+
// You can parse the transaction object if you need to.
4+
}`
5+
6+
export {js}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const js = `onSuccess: (response) => {
2+
// Post payment flow can go here
3+
}`
4+
5+
export {js}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const js = `const popup = new Paystack()
2+
3+
const transaction = popup.newTransaction({
4+
key: 'pk_domain_xxxxx', // Replace with your public key
5+
6+
amount: 10000,
7+
onLoad: (transaction) => {
8+
window.clearInterval(redirectTimer);
9+
}
10+
});
11+
12+
let timeElapsed = 0;
13+
const timeLimit = 2;
14+
const redirectURL = 'https://your.redirecturl.com';
15+
const redirectTimer = setInterval(() => {
16+
timeElapsed += 1;
17+
if (timeElapsed === timeLimit) {
18+
popup.cancelTransaction(transaction.id);
19+
window.location.href = redirectURL;
20+
}
21+
}, 1000);`
22+
23+
export {js}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const js = `const popup = new Paystack()
2+
3+
popup.checkout({
4+
key: 'pk_domain_xxxxxx',
5+
6+
amount: 23400,
7+
onSuccess: (transaction) => {
8+
console.log(transaction);
9+
},
10+
onLoad: (response) => {
11+
console.log("onLoad: ", response);
12+
},
13+
onCancel: () => {
14+
console.log("onCancel");
15+
},
16+
onError: (error) => {
17+
console.log(`Error ${error.message}`);
18+
}
19+
})`
20+
21+
export {js}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const js = `// Add for NPM, Yarn
2+
import Paystack from '@paystack/inline-js';
3+
4+
const popup = new Paystack()`
5+
6+
export {js}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const cdn = `<script src="https://js.paystack.co/v2/inline.js"></script>`
2+
3+
const npm = `npm i @paystack/inline-js`
4+
5+
const yarn = `yarn add @paystack/inline-js`
6+
7+
export {cdn, npm, yarn}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const js = `const popup = new Paystack()
2+
3+
popup.newTransaction({
4+
key: 'pk_domain_xxxxxx',
5+
6+
amount: 98540,
7+
split_code: 'SPL_RYUUL4u1hP',
8+
onSuccess: (transaction) => {
9+
console.log(transaction);
10+
},
11+
onLoad: (response) => {
12+
console.log("onLoad: ", response);
13+
},
14+
onCancel: () => {
15+
console.log("onCancel");
16+
},
17+
onError: (error) => {
18+
console.log(`Error: ${error.message}`);
19+
}
20+
})`
21+
22+
export {js}

0 commit comments

Comments
 (0)