Skip to content
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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# MakePay for Medusa

[![npm version](https://img.shields.io/npm/v/@makecrypto/medusa-plugin-makepay.svg)](https://www.npmjs.com/package/@makecrypto/medusa-plugin-makepay)
[![CI](https://github.com/makecryptoio/medusa-plugin-makepay/actions/workflows/ci.yml/badge.svg)](https://github.com/makecryptoio/medusa-plugin-makepay/actions/workflows/ci.yml)
[![CI](https://github.com/makepay-io/medusa-plugin-makepay/actions/workflows/ci.yml/badge.svg)](https://github.com/makepay-io/medusa-plugin-makepay/actions/workflows/ci.yml)

<p align="center">
<img src="./assets/makepay-medusa-icon.png" alt="MakePay icon" width="96" height="96" />
Expand All @@ -11,6 +11,10 @@ Official MakePay payment provider for Medusa v2. The provider creates hosted
MakePay checkout links for Medusa payment sessions and reconciles payment
status through signed MakePay webhooks.

Need MakePay credentials? Register your merchant account at
[makepay.io](https://makepay.io) before configuring this plugin. Your merchant
account provides the API key and webhook secret used below.

## Install

```bash
Expand Down Expand Up @@ -73,6 +77,7 @@ webhook secret as `MAKEPAY_WEBHOOK_SECRET`.
| `returnUrl` | no | Fallback return URL for MakePay checkout. |
| `successUrl` | no | Success return URL for MakePay checkout. |
| `failureUrl` | no | Failure return URL for MakePay checkout. |
| `webhookToleranceSeconds` | no | Signature timestamp tolerance for MakePay webhooks. |

## Storefront flow

Expand All @@ -86,6 +91,10 @@ paymentSession.data.next_action
Redirect shoppers to that URL, then use MakePay webhooks to update the Medusa
payment session when the payment is completed, canceled, or failed.

If Medusa updates an unpaid payment session because the cart amount or fiat
currency changed, the provider archives the old MakePay link and creates a new
hosted checkout link for the updated session.

## Development

```bash
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@makecrypto/medusa-plugin-makepay",
"version": "0.1.2",
"description": "Official MakePay payment provider for Medusa v2 hosted checkout.",
"version": "0.2.0",
"description": "Official MakePay payment provider for Medusa v2 hosted checkout. Register a merchant account at https://makepay.io.",
"license": "MIT",
"author": "MakePay",
"homepage": "https://github.com/makecryptoio/medusa-plugin-makepay#readme",
"homepage": "https://makepay.io",
"bugs": {
"url": "https://github.com/makecryptoio/medusa-plugin-makepay/issues"
"url": "https://github.com/makepay-io/medusa-plugin-makepay/issues"
},
"type": "module",
"sideEffects": false,
Expand Down Expand Up @@ -37,7 +37,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/makecryptoio/medusa-plugin-makepay.git"
"url": "git+https://github.com/makepay-io/medusa-plugin-makepay.git"
},
"keywords": [
"medusa-plugin",
Expand Down
11 changes: 11 additions & 0 deletions src/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ declare module "@makecrypto/makepay" {
uid?: string;
publicUrl?: string;
checkoutUrl?: string;
public_url?: string;
checkout_url?: string;
url?: string;
status?: string;
amount?: string | number | null;
amountUsd?: string | number | null;
currency?: string | null;
fiatCurrency?: string | null;
fiat_currency?: string | null;
metadata?: Record<string, unknown>;
payload?: Record<string, unknown>;
[key: string]: unknown;
Expand All @@ -33,6 +38,12 @@ declare module "@makecrypto/makepay" {
export type MakePayPaymentLinkResponse = {
paymentLink?: MakePayPaymentLink;
payment_link?: MakePayPaymentLink;
data?: {
paymentLink?: MakePayPaymentLink;
payment_link?: MakePayPaymentLink;
link?: MakePayPaymentLink;
};
link?: MakePayPaymentLink;
[key: string]: unknown;
};

Expand Down
19 changes: 19 additions & 0 deletions src/providers/makepay/services/makepay-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
mapMakePayWebhookToPaymentAction,
normalizeAmountValue,
normalizeProviderOptions,
shouldRefreshPaymentLinkForUpdate,
validateMakePayProviderOptions,
} from "../utils.js";

Expand Down Expand Up @@ -119,7 +120,9 @@ class MakePayProviderService extends AbstractPaymentProvider<MakePayProviderOpti
return {
id: uid,
data: buildProviderData({
amount: payload.amount,
existing: data,
fiatCurrency: currency_code.toUpperCase(),
paymentLink,
sessionId,
status: "requires_more",
Expand Down Expand Up @@ -179,6 +182,22 @@ class MakePayProviderService extends AbstractPaymentProvider<MakePayProviderOpti
}

const providerData = await this.retrieveProviderData(data);
if (
shouldRefreshPaymentLinkForUpdate({
currentData: providerData,
nextAmount: amount,
nextCurrencyCode: currency_code,
})
) {
await this.archivePaymentLink(providerData);

return this.initiatePayment({
amount,
context,
currency_code,
data: providerData,
}) as Promise<UpdatePaymentOutput>;
}

return {
data: providerData,
Expand Down
3 changes: 3 additions & 0 deletions src/providers/makepay/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export type NormalizedMakePayProviderOptions = Required<

export type MakePayProviderData = Record<string, unknown> & {
id?: string;
amount?: string | number;
fiat_currency?: string;
fiatCurrency?: string;
payment_link_uid?: string;
public_url?: string;
checkout_url?: string;
Expand Down
Loading
Loading