Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add InlineJS snippets #79

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dist/doc/developer-tools/inlinejs/callback-oncancel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const js = `onCancel: () => {
console.log("User cancelled")
}`

export {js}
9 changes: 9 additions & 0 deletions dist/doc/developer-tools/inlinejs/callback-onelementsmount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const js = `onElementsMount: (elements) =>{ // { applePay: true } or null
if (elements) {
console.log(`Successfully mounted elements: ${JSON.stringify(elements)}`);
} else {
console.log('Could not load elements');
}
}`

export {js}
5 changes: 5 additions & 0 deletions dist/doc/developer-tools/inlinejs/callback-onerror.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const js = `onError: (error) => {
console.log(`Error: ${error.message}`);
}`

export {js}
6 changes: 6 additions & 0 deletions dist/doc/developer-tools/inlinejs/callback-onload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const js = `onLoad: (response) => {
// Transaction has loaded
// You can parse the transaction object if you need to.
}`

export {js}
5 changes: 5 additions & 0 deletions dist/doc/developer-tools/inlinejs/callback-onsuccess.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const js = `onSuccess: (response) => {
// Post payment flow can go here
}`

export {js}
23 changes: 23 additions & 0 deletions dist/doc/developer-tools/inlinejs/cancel-payment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const js = `const popup = new Paystack()

const transaction = popup.newTransaction({
key: 'pk_domain_xxxxx', // Replace with your public key
email: "[email protected]",
amount: 10000,
onLoad: (transaction) => {
window.clearInterval(redirectTimer);
}
});

let timeElapsed = 0;
const timeLimit = 2;
const redirectURL = 'https://your.redirecturl.com';
const redirectTimer = setInterval(() => {
timeElapsed += 1;
if (timeElapsed === timeLimit) {
popup.cancelTransaction(transaction.id);
window.location.href = redirectURL;
}
}, 1000);`

export {js}
21 changes: 21 additions & 0 deletions dist/doc/developer-tools/inlinejs/checkout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const js = `const popup = new Paystack()

popup.checkout({
key: 'pk_domain_xxxxxx',
email: '[email protected]',
amount: 23400,
onSuccess: (transaction) => {
console.log(transaction);
},
onLoad: (response) => {
console.log("onLoad: ", response);
},
onCancel: () => {
console.log("onCancel");
},
onError: (error) => {
console.log(`Error ${error.message}`);
}
})`

export {js}
6 changes: 6 additions & 0 deletions dist/doc/developer-tools/inlinejs/initialize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const js = `// Add for NPM, Yarn
import Paystack from '@paystack/inline-js';

const popup = new Paystack()`

export {js}
7 changes: 7 additions & 0 deletions dist/doc/developer-tools/inlinejs/installation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const cdn = `<script src="https://js.paystack.co/v2/inline.js"></script>`

const npm = `npm i @paystack/inline-js`

const yarn = `yarn add @paystack/inline-js`

export {cdn, npm, yarn}
22 changes: 22 additions & 0 deletions dist/doc/developer-tools/inlinejs/multi-split-dynamic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const js = `const popup = new Paystack()

popup.newTransaction({
key: 'pk_domain_xxxxxx',
email: '[email protected]',
amount: 98540,
split_code: 'SPL_RYUUL4u1hP',
onSuccess: (transaction) => {
console.log(transaction);
},
onLoad: (response) => {
console.log("onLoad: ", response);
},
onCancel: () => {
console.log("onCancel");
},
onError: (error) => {
console.log(`Error: ${error.message}`);
}
})`

export {js}
36 changes: 36 additions & 0 deletions dist/doc/developer-tools/inlinejs/multi-split.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const js = `const popup = new Paystack()

popup.newTransaction({
key: 'pk_domain_xxxxxx',
email: '[email protected]',
amount: 35650,
currency: 'NGN',
split: {
type: 'percentage',
bearer_type: 'account',
subaccounts: [
{
subaccount: 'ACCT_dskvlw3y3dsvkmt',
share: 30
},
{
subaccount: 'ACCT_eg4sob4590pq9vb',
share: 20
}
]
},
onSuccess: (transaction) => {
console.log(transaction);
},
onLoad: (response) => {
console.log("onLoad: ", response);
},
onCancel: () => {
console.log("onCancel");
},
onError: (error) => {
console.log(`Error: ${error.message}`);
}
})`

export {js}
21 changes: 21 additions & 0 deletions dist/doc/developer-tools/inlinejs/new-transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const js = `const popup = new Paystack()

popup.newTransaction({
key: 'pk_domain_xxxxxx',
email: '[email protected]',
amount: 23400,
onSuccess: (transaction) => {
console.log(transaction);
},
onLoad: (response) => {
console.log("onLoad: ", response);
},
onCancel: () => {
console.log("onCancel");
},
onError: (error) => {
console.log(`Error: ${error.message}`);
}
})`

export {js}
33 changes: 33 additions & 0 deletions dist/doc/developer-tools/inlinejs/payment-request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const js = `const popup = new Paystack()

const onElementsMount = (elements) => {
if (elements && elements.applePay) {
document.querySelector("#pay-button").innerText = "More Payment Options";
}
}

try {
await popup.paymentRequest({
key: 'pk_domain_xxxxxx',
email: '[email protected]',
amount: 10000,
currency: "NGN",
container: 'payment-request-buttons',
loadPaystackCheckoutButton: 'pay-button',
styles: {
theme: 'dark',
applePay: {
width: '100%',
height: '50px',
borderRadius: '3px',
type: 'plain',
locale: 'en'
}
},
onElementsMount,
});
} catch (error) {

}`

export {js}
12 changes: 12 additions & 0 deletions dist/doc/developer-tools/inlinejs/preload-transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const js = `const popup = new Paystack()

const loadPopup = popup.preloadTransaction({
key: 'pk_domain_xxxxxx',
email: '[email protected]',
amount: 10000,
currency: "NGN"
});

document.querySelector("#make-payment").onclick = loadPopup;`

export {js}
5 changes: 5 additions & 0 deletions dist/doc/developer-tools/inlinejs/resume-transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const js = `const popup = new Paystack()

popup.resumeTransaction(access_code)`

export {js}
22 changes: 22 additions & 0 deletions dist/doc/developer-tools/inlinejs/split.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const js = `const popup = new Paystack()

popup.newTransaction({
key: 'pk_domain_xxxxxx',
email: '[email protected]',
amount: 45000,
subaccountCode: 'ACCT_dskvlw3y3dsvkmt',
onSuccess: (transaction) => {
console.log(transaction);
},
onLoad: (response) => {
console.log("onLoad: ", response);
},
onCancel: () => {
console.log("onCancel");
},
onError: (error) => {
console.log(`Error: ${error.message}`);
}
})`

export {js}
22 changes: 22 additions & 0 deletions dist/doc/developer-tools/inlinejs/subscription-plan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const js = `const popup = new Paystack()

popup.newTransaction({
key: 'pk_domain_xxxxxx',
email: '[email protected]',
amount: 40000,
planCode: 'PLN_l6aglbqzebn32c6',
onSuccess: (transaction) => {
console.log(transaction);
},
onLoad: (response) => {
console.log("onLoad: ", response);
},
onCancel: () => {
console.log("onCancel");
},
onError: () => {
console.log("onError");
}
})`

export {js}
22 changes: 22 additions & 0 deletions dist/doc/developer-tools/inlinejs/subscription.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const js = `const popup = new Paystack()

popup.newTransaction({
key: 'pk_domain_xxxxxx',
email: '[email protected]',
amount: 20000,
planInterval: 'weekly',
onSuccess: (transaction) => {
console.log(transaction);
},
onLoad: (response) => {
console.log("onLoad: ", response);
},
onCancel: () => {
console.log("onCancel");
},
onError: () => {
console.log("onError");
}
})`

export {js}
2 changes: 2 additions & 0 deletions src/doc/developer-tools/inlinejs/callback-oncancel/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
languages:
- js
3 changes: 3 additions & 0 deletions src/doc/developer-tools/inlinejs/callback-oncancel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
onCancel: () => {
console.log("User cancelled")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
languages:
- js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
onElementsMount: (elements) =>{ // { applePay: true } or null
if (elements) {
console.log(`Successfully mounted elements: ${JSON.stringify(elements)}`);
} else {
console.log('Could not load elements');
}
}
2 changes: 2 additions & 0 deletions src/doc/developer-tools/inlinejs/callback-onerror/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
languages:
- js
3 changes: 3 additions & 0 deletions src/doc/developer-tools/inlinejs/callback-onerror/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
onError: (error) => {
console.log(`Error: ${error.message}`);
}
2 changes: 2 additions & 0 deletions src/doc/developer-tools/inlinejs/callback-onload/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
languages:
- js
4 changes: 4 additions & 0 deletions src/doc/developer-tools/inlinejs/callback-onload/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
onLoad: (response) => {
// Transaction has loaded
// You can parse the transaction object if you need to.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
languages:
- js
3 changes: 3 additions & 0 deletions src/doc/developer-tools/inlinejs/callback-onsuccess/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
onSuccess: (response) => {
// Post payment flow can go here
}
2 changes: 2 additions & 0 deletions src/doc/developer-tools/inlinejs/cancel-payment/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
languages:
- js
21 changes: 21 additions & 0 deletions src/doc/developer-tools/inlinejs/cancel-payment/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const popup = new Paystack()

const transaction = popup.newTransaction({
key: 'pk_domain_xxxxx', // Replace with your public key
email: "[email protected]",
amount: 10000,
onLoad: (transaction) => {
window.clearInterval(redirectTimer);
}
});

let timeElapsed = 0;
const timeLimit = 2;
const redirectURL = 'https://your.redirecturl.com';
const redirectTimer = setInterval(() => {
timeElapsed += 1;
if (timeElapsed === timeLimit) {
popup.cancelTransaction(transaction.id);
window.location.href = redirectURL;
}
}, 1000);
2 changes: 2 additions & 0 deletions src/doc/developer-tools/inlinejs/checkout/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
languages:
- js
Loading