Skip to content

Commit

Permalink
fix: remove currency restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
a11rew committed Jan 13, 2024
1 parent fa91323 commit ae3f776
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
4 changes: 2 additions & 2 deletions packages/plugin/src/services/paystack-payment-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
CartService,
} from "@medusajs/medusa";
import { MedusaError, MedusaErrorTypes } from "@medusajs/utils";
import { validateCurrencyCode } from "../utils/currencyCode";
import { formatCurrencyCode } from "../utils/currencyCode";

export interface PaystackPaymentProcessorConfig {
/**
Expand Down Expand Up @@ -94,7 +94,7 @@ class PaystackPaymentProcessor extends AbstractPaymentProcessor {

const { amount, email, currency_code } = context;

const validatedCurrencyCode = validateCurrencyCode(currency_code);
const validatedCurrencyCode = formatCurrencyCode(currency_code);

const { data, status, message } =
await this.paystack.transaction.initialize({
Expand Down
29 changes: 4 additions & 25 deletions packages/plugin/src/utils/currencyCode.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
import { MedusaError, MedusaErrorTypes } from "@medusajs/utils";
export function formatCurrencyCode(currencyCode: string) {
// Uppercase the currency code
const formattedCurrencyCode = currencyCode.toUpperCase();

export const supportedCurrencies = ["NGN", "GHS", "ZAR", "USD"] as const;

export type SupportedCurrency = (typeof supportedCurrencies)[number];

export function isSupportedCurrency(
currencyCode: string,
): currencyCode is SupportedCurrency {
return supportedCurrencies.includes(currencyCode as SupportedCurrency);
}

export function validateCurrencyCode(currencyCode: string): SupportedCurrency {
if (!isSupportedCurrency(currencyCode)) {
// Try uppercasing the code
if (isSupportedCurrency(currencyCode.toUpperCase())) {
return currencyCode.toUpperCase() as SupportedCurrency;
}

throw new MedusaError(
MedusaErrorTypes.INVALID_ARGUMENT,
`Unsupported currency code provided to Paystack Paystack Payment Provider: ${currencyCode}`,
);
}

return currencyCode as SupportedCurrency;
return formattedCurrencyCode;
}

0 comments on commit ae3f776

Please sign in to comment.