contipay-js
v1.0.1
Published
ContiPay JS Client
Readme
ContiPay JavaScript Client Documentation
Requirements
ContiPay Account
ContiPay Secret and Key
How it Works
1. Install latest version
npm install contipay-js2. Import Classes
// Import necessary classes
const Contipay = require("contipay-js/src/contipay");
const SimpleDirectMethod = require("contipay-js/src/helpers/simple_direct_method");
const DirectMethod = require("contipay-js/src/helpers/direct_method");
const SimpleRedirectMethod = require("contipay-js/src/helpers/simple_redirect_method");
const RedirectMethod = require("contipay-js/src/helpers/redirect_method");3. Process Payment
i. Basic Direct Payment Example
const contipay = new Contipay("token-here", "secret-here");
const phone = "263782000340";
const payload = new SimpleDirectMethod(merchantCode, webhookUrl)
.setUpProvider("InnBucks", "IB")
.preparePayload(amount, phone);
contipay
.setAppMode("DEV") // LIVE as another option
.setPaymentMethod()
.process(payload)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error(error);
});ii. Basic Redirect Payment Example
const contipay = new Contipay("token-here", "secret-here");
const phone = "263782000340";
const payload = new SimpleRedirectMethod(
merchantCode,
webhookUrl,
successUrl,
cancelUrl
).preparePayload(amount, phone);
contipay
.setAppMode("DEV") // LIVE as another option
.setPaymentMethod("redirect")
.process(payload)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error(error);
});iii. Direct Payment Example
const contipay = new Contipay("token-here", "secret-here");
const phone = "263782000340";
const payload = new DirectMethod(merchantCode, webhookUrl)
.setUpCustomer("Nigel", "Jaure", phone, "ZW", "[email protected]")
.setUpProvider("Ecocash", "EC")
.setUpAccountDetails(phone, "Nigel Jaure")
.setUpTransaction(amount, "USD")
.preparePayload();
contipay
.setAppMode("DEV")
.setPaymentMethod()
.process(payload)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error(error);
});iv. Redirect Payment Example
const contipay = new Contipay("token-here", "secret-here");
const phone = "263782000340";
const payload = new RedirectMethod(
merchantCode,
webhookUrl,
successUrl,
cancelUrl
)
.setUpCustomer("Nigel", "Jaure", phone, "ZW", "[email protected]")
.setUpTransaction(amount, "USD")
.preparePayload();
contipay
.setAppMode("DEV")
.setPaymentMethod("redirect")
.process(payload)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error(error);
});Additional Notes
- The
updateURLmethod is optional and applicable only if the URL has changed. Use it to update the URLs accordingly. Here's how you can use it:
const contipay = new Contipay("token-here", "secret-here");
// Update URLs if necessary
contipay.updateURL("dev-url", "live-url");
// Process payment with the updated URLs
contipay
.setAppMode("DEV") // LIVE as another option
.setPaymentMethod()
.process(payload)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error(error);
});Ensure to set the appropriate mode (
DEVorLIVE) using thesetAppModemethod before processing payments.The provided examples cover basic scenarios, including direct and redirect payment methods, customer information setup, and transaction details.
