@tecafrik/africa-payment-sdk
Version:
A single SDK to integrate all african payment providers seamlessly
594 lines • 29.3 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const payment_provider_interface_1 = require("../../payment-provider.interface");
const paydunya_fixtures_1 = require("../fixtures/paydunya.fixtures");
const paydunya_1 = __importDefault(require("../paydunya"));
const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
let paydunyaPaymentProvider;
let mockApi;
jest.mock("apisauce", () => {
const realApisauce = jest.requireActual("apisauce");
return Object.assign(Object.assign({}, realApisauce), { create: jest.fn((config) => {
const api = realApisauce.create(config);
mockApi = new axios_mock_adapter_1.default(api.axiosInstance);
return api;
}) });
});
beforeEach(() => {
paydunyaPaymentProvider = new paydunya_1.default({
masterKey: "masterKey",
mode: "live",
privateKey: "privateKey",
publicKey: "publicKey",
store: {
name: "store-name",
},
token: "token",
callbackUrl: "https://example.com/callback",
});
});
afterEach(() => {
mockApi.reset();
});
test("calls wave API and returns a checkout result on success", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi
.onPost("/v1/softpay/wave-senegal")
.replyOnce(200, paydunya_fixtures_1.wavePaymentSuccessResponse);
const checkoutResult = yield paydunyaPaymentProvider.checkoutMobileMoney({
amount: 100,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Mamadou",
lastName: "Diallo",
phoneNumber: "+221781234567",
},
description: "description",
paymentMethod: payment_provider_interface_1.PaymentMethod.WAVE,
transactionId: "transactionId",
successRedirectUrl: "https://example.com/success",
failureRedirectUrl: "https://example.com/failure",
metadata: {
text_meta: "value",
number_meta: 1,
boolean_meta: true,
},
});
expect(mockApi.history).toMatchSnapshot();
expect(checkoutResult).toMatchSnapshot();
}));
test("calls orange money API and returns a checkout result on success", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi
.onPost("/v1/softpay/new-orange-money-senegal")
.replyOnce(200, paydunya_fixtures_1.orangeMoneySuccessResponse);
const checkoutResult = yield paydunyaPaymentProvider.checkoutMobileMoney({
amount: 100,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Mamadou",
lastName: "Diallo",
phoneNumber: "+221781234567",
},
description: "description",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "transactionId",
authorizationCode: "12345",
successRedirectUrl: "https://example.com/success",
failureRedirectUrl: "https://example.com/failure",
metadata: {
text_meta: "value",
number_meta: 1,
boolean_meta: true,
},
});
expect(mockApi.history).toMatchSnapshot();
expect(checkoutResult).toMatchSnapshot();
}));
test("calls paydunya cc API and returns a checkout result on success", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.creditCardInvoiceSuccessResponse);
const checkoutResult = yield paydunyaPaymentProvider.checkoutCreditCard({
amount: 100,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Mamadou",
lastName: "Diallo",
email: "mamadou.diallo@yopmail.com",
},
description: "description",
paymentMethod: payment_provider_interface_1.PaymentMethod.CREDIT_CARD,
transactionId: "transactionId",
successRedirectUrl: "https://example.com/success",
failureRedirectUrl: "https://example.com/failure",
metadata: {
text_meta: "value",
number_meta: 1,
boolean_meta: true,
},
});
expect(mockApi.history).toMatchSnapshot();
expect(checkoutResult).toMatchSnapshot();
}));
test("emits a payment initiated event when given an event emitter", () => __awaiter(void 0, void 0, void 0, function* () {
const eventEmitter = {
emit: jest.fn(),
};
paydunyaPaymentProvider.useEventEmitter(eventEmitter);
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi
.onPost("/v1/softpay/wave-senegal")
.replyOnce(200, paydunya_fixtures_1.wavePaymentSuccessResponse);
yield paydunyaPaymentProvider.checkoutMobileMoney({
amount: 100,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Mamadou",
lastName: "Diallo",
phoneNumber: "+221781234567",
},
description: "description",
paymentMethod: payment_provider_interface_1.PaymentMethod.WAVE,
transactionId: "transactionId",
metadata: {
text_meta: "value",
number_meta: 1,
boolean_meta: true,
},
});
expect(eventEmitter.emit).toMatchSnapshot();
}));
test("throws unsupported payment method error when using checkout redirect", () => __awaiter(void 0, void 0, void 0, function* () {
yield expect(paydunyaPaymentProvider.checkoutRedirect({
amount: 100,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Mamadou",
lastName: "Diallo",
email: "mamadou.diallo@yopmail.com",
},
description: "description",
paymentMethod: payment_provider_interface_1.PaymentMethod.CREDIT_CARD,
transactionId: "transactionId",
successRedirectUrl: "https://example.com/success",
failureRedirectUrl: "https://example.com/failure",
})).rejects.toThrowErrorMatchingSnapshot();
}));
test("refunds a wave transaction properly", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onGet(/\/v1\/checkout-invoice\/confirm\/.+/)
.reply(200, paydunya_fixtures_1.getWaveInvoiceSuccessResponse);
mockApi
.onPost("/v2/disburse/get-invoice")
.reply(200, paydunya_fixtures_1.createDisburseInvoiceSuccessResponse);
mockApi
.onPost("/v2/disburse/submit-invoice")
.reply(200, paydunya_fixtures_1.submitDisburseInvoiceSuccessResponse);
const refundResult = yield paydunyaPaymentProvider.refund({
transactionId: "transactionId",
refundedTransactionReference: "wave-transaction-reference",
});
expect(mockApi.history).toMatchSnapshot();
expect(refundResult).toMatchSnapshot();
}));
test("makes a payout to the provided customer", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v2/disburse/get-invoice")
.reply(200, paydunya_fixtures_1.createDisburseInvoiceSuccessResponse);
mockApi
.onPost("/v2/disburse/submit-invoice")
.reply(200, paydunya_fixtures_1.submitDisburseInvoiceSuccessResponse);
const payoutResult = yield paydunyaPaymentProvider.payoutMobileMoney({
amount: 150,
currency: payment_provider_interface_1.Currency.XOF,
paymentMethod: payment_provider_interface_1.PaymentMethod.WAVE,
recipient: {
phoneNumber: "+221781234567",
},
transactionId: "transactionId",
transactionReference: "transactionReference",
metadata: {
text_meta: "value",
number_meta: 1,
boolean_meta: true,
},
});
expect(mockApi.history).toMatchSnapshot();
expect(payoutResult).toMatchSnapshot();
}));
describe("Orange Money flow detection", () => {
test("selects OTPCODE flow when authorizationCode is provided", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi
.onPost("/v1/softpay/new-orange-money-senegal")
.replyOnce(200, paydunya_fixtures_1.orangeMoneySuccessResponse);
yield paydunyaPaymentProvider.checkoutMobileMoney({
amount: 100,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Mamadou",
lastName: "Diallo",
phoneNumber: "+221781234567",
},
description: "description",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "transactionId",
authorizationCode: "123456",
});
const orangeMoneyRequest = mockApi.history.post.find((req) => req.url === "/v1/softpay/new-orange-money-senegal");
const requestData = JSON.parse((orangeMoneyRequest === null || orangeMoneyRequest === void 0 ? void 0 : orangeMoneyRequest.data) || "{}");
expect(requestData.api_type).toBe("OTPCODE");
expect(requestData.authorization_code).toBe("123456");
}));
test("selects QRCODE flow when authorizationCode is undefined", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi
.onPost("/v1/softpay/new-orange-money-senegal")
.replyOnce(200, paydunya_fixtures_1.orangeMoneySuccessResponse);
yield paydunyaPaymentProvider.checkoutMobileMoney({
amount: 100,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Mamadou",
lastName: "Diallo",
phoneNumber: "+221781234567",
},
description: "description",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "transactionId",
// authorizationCode is undefined
});
const orangeMoneyRequest = mockApi.history.post.find((req) => req.url === "/v1/softpay/new-orange-money-senegal");
const requestData = JSON.parse((orangeMoneyRequest === null || orangeMoneyRequest === void 0 ? void 0 : orangeMoneyRequest.data) || "{}");
expect(requestData.api_type).toBe("QRCODE");
expect(requestData.authorization_code).toBeUndefined();
}));
test("selects QRCODE flow when authorizationCode is empty string", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi
.onPost("/v1/softpay/new-orange-money-senegal")
.replyOnce(200, paydunya_fixtures_1.orangeMoneySuccessResponse);
yield paydunyaPaymentProvider.checkoutMobileMoney({
amount: 100,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Mamadou",
lastName: "Diallo",
phoneNumber: "+221781234567",
},
description: "description",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "transactionId",
authorizationCode: "",
});
const orangeMoneyRequest = mockApi.history.post.find((req) => req.url === "/v1/softpay/new-orange-money-senegal");
const requestData = JSON.parse((orangeMoneyRequest === null || orangeMoneyRequest === void 0 ? void 0 : orangeMoneyRequest.data) || "{}");
expect(requestData.api_type).toBe("QRCODE");
expect(requestData.authorization_code).toBeUndefined();
}));
});
describe("Orange Money request payload builder", () => {
test("OTPCODE request includes all common fields correctly", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi
.onPost("/v1/softpay/new-orange-money-senegal")
.replyOnce(200, paydunya_fixtures_1.orangeMoneySuccessResponse);
yield paydunyaPaymentProvider.checkoutMobileMoney({
amount: 100,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Mamadou",
lastName: "Diallo",
phoneNumber: "+221781234567",
},
description: "description",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "transactionId",
authorizationCode: "123456",
});
const orangeMoneyRequest = mockApi.history.post.find((req) => req.url === "/v1/softpay/new-orange-money-senegal");
const requestData = JSON.parse((orangeMoneyRequest === null || orangeMoneyRequest === void 0 ? void 0 : orangeMoneyRequest.data) || "{}");
expect(requestData.customer_name).toBe("Mamadou Diallo");
expect(requestData.customer_email).toBe("+221781234567@yopmail.com");
expect(requestData.phone_number).toBe("781234567");
expect(requestData.invoice_token).toBe(paydunya_fixtures_1.createInvoiceSuccessResponse.token);
expect(requestData.api_type).toBe("OTPCODE");
expect(requestData.authorization_code).toBe("123456");
}));
test("QRCODE request includes all common fields correctly and excludes authorization_code", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi
.onPost("/v1/softpay/new-orange-money-senegal")
.replyOnce(200, paydunya_fixtures_1.orangeMoneySuccessResponse);
yield paydunyaPaymentProvider.checkoutMobileMoney({
amount: 100,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Mamadou",
lastName: "Diallo",
phoneNumber: "+221781234567",
},
description: "description",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "transactionId",
// authorizationCode not provided
});
const orangeMoneyRequest = mockApi.history.post.find((req) => req.url === "/v1/softpay/new-orange-money-senegal");
const requestData = JSON.parse((orangeMoneyRequest === null || orangeMoneyRequest === void 0 ? void 0 : orangeMoneyRequest.data) || "{}");
expect(requestData.customer_name).toBe("Mamadou Diallo");
expect(requestData.customer_email).toBe("+221781234567@yopmail.com");
expect(requestData.phone_number).toBe("781234567");
expect(requestData.invoice_token).toBe(paydunya_fixtures_1.createInvoiceSuccessResponse.token);
expect(requestData.api_type).toBe("QRCODE");
expect(requestData).not.toHaveProperty("authorization_code");
}));
});
describe("Orange Money QR code payment flow", () => {
test("successful QR code payment with redirect URL in response", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi
.onPost("/v1/softpay/new-orange-money-senegal")
.replyOnce(200, paydunya_fixtures_1.orangeMoneyQrCodeSuccessResponseWithUrl);
const checkoutResult = yield paydunyaPaymentProvider.checkoutMobileMoney({
amount: 5000,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Alioune",
lastName: "Faye",
phoneNumber: "+221774563209",
},
description: "QR code payment test",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "test-txn-qr-001",
// No authorizationCode - triggers QRCODE flow
});
expect(checkoutResult.redirectUrl).toBe("https://qr.paydunya.com/checkout?token=qr-token-123");
expect(checkoutResult.transactionStatus).toBe(payment_provider_interface_1.TransactionStatus.PENDING);
expect(checkoutResult.transactionAmount).toBe(5000);
expect(checkoutResult.transactionCurrency).toBe(payment_provider_interface_1.Currency.XOF);
expect(checkoutResult.transactionId).toBe("test-txn-qr-001");
}));
test("successful QR code payment without redirect URL", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi
.onPost("/v1/softpay/new-orange-money-senegal")
.replyOnce(200, paydunya_fixtures_1.orangeMoneyQrCodeSuccessResponseWithoutUrl);
const checkoutResult = yield paydunyaPaymentProvider.checkoutMobileMoney({
amount: 3000,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Alioune",
lastName: "Faye",
phoneNumber: "+221774563209",
},
description: "QR code payment without URL",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "test-txn-qr-002",
// No authorizationCode - triggers QRCODE flow
});
expect(checkoutResult.redirectUrl).toBeUndefined();
expect(checkoutResult.transactionStatus).toBe(payment_provider_interface_1.TransactionStatus.PENDING);
expect(checkoutResult.transactionAmount).toBe(3000);
expect(checkoutResult.transactionCurrency).toBe(payment_provider_interface_1.Currency.XOF);
expect(checkoutResult.transactionId).toBe("test-txn-qr-002");
}));
test("QR code payment error handling", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi.onPost("/v1/softpay/new-orange-money-senegal").replyOnce(500, {
success: false,
message: "Payment processing failed",
});
yield expect(paydunyaPaymentProvider.checkoutMobileMoney({
amount: 2000,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Alioune",
lastName: "Faye",
phoneNumber: "+221774563209",
},
description: "QR code payment error test",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "test-txn-qr-error",
// No authorizationCode - triggers QRCODE flow
})).rejects.toThrow("Payment processing failed");
}));
test("CheckoutResult includes redirectUrl when provided by API", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi
.onPost("/v1/softpay/new-orange-money-senegal")
.replyOnce(200, paydunya_fixtures_1.orangeMoneyQrCodeSuccessResponseWithUrl);
const checkoutResult = yield paydunyaPaymentProvider.checkoutMobileMoney({
amount: 7500,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Alioune",
lastName: "Faye",
phoneNumber: "+221774563209",
},
description: "QR code with redirect URL",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "test-txn-qr-003",
});
// Verify that redirectUrl is properly included in CheckoutResult
expect(checkoutResult).toHaveProperty("redirectUrl");
expect(checkoutResult.redirectUrl).toBe("https://qr.paydunya.com/checkout?token=qr-token-123");
// Verify all other required fields are present
expect(checkoutResult).toHaveProperty("transactionId");
expect(checkoutResult).toHaveProperty("transactionReference");
expect(checkoutResult).toHaveProperty("transactionStatus");
expect(checkoutResult).toHaveProperty("transactionAmount");
expect(checkoutResult).toHaveProperty("transactionCurrency");
}));
});
describe("Backward compatibility", () => {
test("existing code with authorizationCode still works correctly", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi
.onPost("/v1/softpay/new-orange-money-senegal")
.replyOnce(200, paydunya_fixtures_1.orangeMoneySuccessResponse);
// This is how existing code would call the API with authorizationCode
const checkoutResult = yield paydunyaPaymentProvider.checkoutMobileMoney({
amount: 100,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Mamadou",
lastName: "Diallo",
phoneNumber: "+221781234567",
},
description: "description",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "transactionId",
authorizationCode: "12345",
successRedirectUrl: "https://example.com/success",
failureRedirectUrl: "https://example.com/failure",
metadata: {
text_meta: "value",
number_meta: 1,
boolean_meta: true,
},
});
// Verify the result structure is consistent with previous implementation
expect(checkoutResult).toHaveProperty("transactionId");
expect(checkoutResult).toHaveProperty("transactionReference");
expect(checkoutResult).toHaveProperty("transactionStatus");
expect(checkoutResult).toHaveProperty("transactionAmount");
expect(checkoutResult).toHaveProperty("transactionCurrency");
expect(checkoutResult.transactionId).toBe("transactionId");
expect(checkoutResult.transactionStatus).toBe(payment_provider_interface_1.TransactionStatus.PENDING);
expect(checkoutResult.transactionAmount).toBe(100);
expect(checkoutResult.transactionCurrency).toBe(payment_provider_interface_1.Currency.XOF);
}));
test("OTPCODE flow produces same results as before", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi
.onPost("/v1/softpay/new-orange-money-senegal")
.replyOnce(200, paydunya_fixtures_1.orangeMoneySuccessResponse);
const checkoutResult = yield paydunyaPaymentProvider.checkoutMobileMoney({
amount: 5000,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Alioune",
lastName: "Faye",
phoneNumber: "+221774563209",
},
description: "Test payment",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "test-backward-compat-001",
authorizationCode: "654321",
});
// Verify the request was made with OTPCODE api_type
const orangeMoneyRequest = mockApi.history.post.find((req) => req.url === "/v1/softpay/new-orange-money-senegal");
const requestData = JSON.parse((orangeMoneyRequest === null || orangeMoneyRequest === void 0 ? void 0 : orangeMoneyRequest.data) || "{}");
expect(requestData.api_type).toBe("OTPCODE");
expect(requestData.authorization_code).toBe("654321");
// Verify the result structure matches expected format
expect(checkoutResult.transactionId).toBe("test-backward-compat-001");
expect(checkoutResult.transactionReference).toBe(paydunya_fixtures_1.createInvoiceSuccessResponse.token);
expect(checkoutResult.transactionStatus).toBe(payment_provider_interface_1.TransactionStatus.PENDING);
expect(checkoutResult.transactionAmount).toBe(5000);
expect(checkoutResult.transactionCurrency).toBe(payment_provider_interface_1.Currency.XOF);
// OTPCODE flow should not have redirectUrl
expect(checkoutResult.redirectUrl).toBeUndefined();
}));
test("error handling remains consistent for invalid authorization code", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi.onPost("/v1/softpay/new-orange-money-senegal").replyOnce(422, {
success: false,
message: "Invalid or expired OTP code!",
});
yield expect(paydunyaPaymentProvider.checkoutMobileMoney({
amount: 1000,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Test",
lastName: "User",
phoneNumber: "+221781234567",
},
description: "Test invalid OTP",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "test-invalid-otp",
authorizationCode: "invalid-code",
})).rejects.toThrow("Invalid or expired OTP code!");
}));
test("error handling remains consistent for general API errors", () => __awaiter(void 0, void 0, void 0, function* () {
mockApi
.onPost("/v1/checkout-invoice/create")
.replyOnce(200, paydunya_fixtures_1.createInvoiceSuccessResponse);
mockApi.onPost("/v1/softpay/new-orange-money-senegal").replyOnce(500, {
success: false,
message: "Internal server error",
});
yield expect(paydunyaPaymentProvider.checkoutMobileMoney({
amount: 2000,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Test",
lastName: "User",
phoneNumber: "+221781234567",
},
description: "Test server error",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "test-server-error",
authorizationCode: "123456",
})).rejects.toThrow("Internal server error");
}));
test("error handling remains consistent for invalid phone number", () => __awaiter(void 0, void 0, void 0, function* () {
yield expect(paydunyaPaymentProvider.checkoutMobileMoney({
amount: 1000,
currency: payment_provider_interface_1.Currency.XOF,
customer: {
firstName: "Test",
lastName: "User",
phoneNumber: "invalid-phone",
},
description: "Test invalid phone",
paymentMethod: payment_provider_interface_1.PaymentMethod.ORANGE_MONEY,
transactionId: "test-invalid-phone",
authorizationCode: "123456",
})).rejects.toThrow();
}));
});
//# sourceMappingURL=paydunya.test.js.map