@mercurjs/payout-stripe-connect 2.0.0-canary.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import * as _mercurjs_types from '@mercurjs/types';
2
+
3
+ declare const _default: _mercurjs_types.ModuleProviderExports;
4
+
5
+ export { _default as default };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import {isPresent,MedusaError,ModuleProvider,Modules,BigNumber,MathBN}from'@medusajs/framework/utils';import {PayoutAccountStatus,PayoutStatus}from'@mercurjs/types';import P from'stripe';function g(o){let t={0:["BIF","CLP","DJF","GNF","JPY","KMF","KRW","MGA","PYG","RWF","UGX","VND","VUV","XAF","XOF","XPF"],3:["BHD","IQD","JOD","KWD","OMR","TND"]};o=o.toUpperCase();let e=2;for(let[r,a]of Object.entries(t))if(a.includes(o)){e=parseInt(r,10);break}return Math.pow(10,e)}function p(o,t){let e=g(t),r=Math.round(new BigNumber(MathBN.mult(o,e)).numeric)/e,i=new BigNumber(MathBN.mult(r,e)).numeric;return e===1e3&&(i=Math.ceil(i/10)*10),parseInt(i.toString().split(".").shift(),10)}var h={detailsSubmitted:true,chargesEnabled:true,payoutsEnabled:true,noOutstandingRequirements:true,requiredCapabilities:[]},u=class{static{this.identifier="stripe-connect";}constructor(t,e){this.config_=e,this.stripe_=new P(e.apiKey);}normalizePayoutParameters(t){let e={};return e.destination=t.id,e.source_transaction=t?.source_transaction,e.transfer_group=t?.order_id,e.description=t?.description,e.metadata=t?.metadata,e}getWebhookResultFromAccount_(t){let e={...h,...this.config_.accountValidation},r=t.requirements,a=r?.disabled_reason,i=!!(r?.currently_due?.length||r?.past_due?.length||r?.pending_verification?.length),m=(e.requiredCapabilities??[]).some(y=>t.capabilities?.[y]!=="active");return a?.startsWith("rejected.")?{action:"account.rejected",data:{id:t.id}}:(!e.detailsSubmitted||t.details_submitted)&&(!e.chargesEnabled||t.charges_enabled)&&(!e.payoutsEnabled||t.payouts_enabled)&&(!e.noOutstandingRequirements||!i)&&!m?{action:"account.activated",data:{id:t.id}}:a?{action:"account.restricted",data:{id:t.id}}:{action:"account.restricted",data:{id:t.id}}}getWebhookResultFromPayout_(t){let e=t.metadata?.payout_id||t.id;switch(t.status){case "pending":case "in_transit":return {action:"payout.processing",data:{id:e}};case "paid":return {action:"payout.paid",data:{id:e}};case "failed":return {action:"payout.failed",data:{id:e}};case "canceled":return {action:"payout.canceled",data:{id:e}};default:return {action:"not_supported"}}}async createPayoutAccount(t){let{data:e}=t,r=e?.country;if(!isPresent(r))throw new MedusaError(MedusaError.Types.INVALID_DATA,'"country" is required');let a=await this.stripe_.accounts.create({type:"express",country:r},{idempotencyKey:t.context?.idempotency_key});return {id:a.id,status:PayoutAccountStatus.PENDING,data:a}}async createPayout(t){let e=this.normalizePayoutParameters(t.data);return {data:await this.stripe_.transfers.create({currency:t.currency_code,amount:p(t.amount,t.currency_code),...e},{idempotencyKey:t.context?.idempotency_key}),status:PayoutStatus.PENDING}}async createOnboarding(t){let e=t?.data?.id;if(!isPresent(e))throw new MedusaError(MedusaError.Types.INVALID_DATA,"'id' is required");if(!isPresent(t.data?.refresh_url))throw new MedusaError(MedusaError.Types.INVALID_DATA,"'refresh_url' is required");if(!isPresent(t.data?.return_url))throw new MedusaError(MedusaError.Types.INVALID_DATA,"'return_url' is required");return {data:await this.stripe_.accountLinks.create({account:e,refresh_url:t.data?.refresh_url,return_url:t.data?.return_url,type:"account_onboarding"},{idempotencyKey:t.context?.idempotency_key})}}async getWebhookActionAndData(t){let e=t.headers["stripe-signature"],r=this.stripe_.webhooks.constructEvent(t.rawData,e,this.config_.webhookSecret);switch(r.type){case "account.updated":return this.getWebhookResultFromAccount_(r.data.object);case "payout.created":case "payout.updated":case "payout.paid":case "payout.failed":case "payout.canceled":return this.getWebhookResultFromPayout_(r.data.object);default:return {action:"not_supported"}}}},l=u;var U=ModuleProvider(Modules.PAYMENT,{services:[l]});export{U as default};//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/index.ts","../src/services/stripe-connect.ts","../src/index.ts"],"names":["getCurrencyMultiplier","currency","currencyMultipliers","power","key","value","getSmallestUnit","amount","multiplier","amount_","BigNumber","MathBN","numeric","DEFAULT_ACCOUNT_VALIDATION","StripeConnectProviderService","_cradle","options","Stripe","extra","res","account","validation","requirements","disabledReason","hasOutstandingRequirements","hasInactiveCapabilities","capability","payout","payoutId","input","data","country","isPresent","MedusaError","response","PayoutAccountStatus","normalizedInput","PayoutStatus","id","payload","signature","event","stripe_connect_default","index_default","ModuleProvider","Modules"],"mappings":"2LAGA,SAASA,CAAAA,CAAsBC,EAAU,CACrC,IAAMC,CAAAA,CAAsB,CACxB,EAAG,CACC,KAAA,CACA,MACA,KAAA,CACA,KAAA,CACA,MACA,KAAA,CACA,KAAA,CACA,KAAA,CACA,KAAA,CACA,MACA,KAAA,CACA,KAAA,CACA,KAAA,CACA,KAAA,CACA,MACA,KACJ,CAAA,CACA,CAAA,CAAG,CAAC,MAAO,KAAA,CAAO,KAAA,CAAO,MAAO,KAAA,CAAO,KAAK,CAChD,CAAA,CAEAD,CAAAA,CAAWA,CAAAA,CAAS,WAAA,GACpB,IAAIE,CAAAA,CAAQ,CAAA,CACZ,IAAA,GAAW,CAACC,CAAAA,CAAKC,CAAK,CAAA,GAAK,MAAA,CAAO,QAAQH,CAAmB,CAAA,CACzD,GAAIG,CAAAA,CAAM,QAAA,CAASJ,CAAQ,CAAA,CAAG,CAC1BE,CAAAA,CAAQ,QAAA,CAASC,EAAK,EAAE,CAAA,CACxB,KACJ,CAEJ,OAAO,IAAA,CAAK,GAAA,CAAI,EAAA,CAAID,CAAK,CAC7B,CASO,SAASG,CAAAA,CACZC,CAAAA,CACAN,EACM,CACN,IAAMO,CAAAA,CAAaR,CAAAA,CAAsBC,CAAQ,CAAA,CAE3CQ,CAAAA,CACF,IAAA,CAAK,KAAA,CAAM,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AwB,CAAA,CAChF,KAAK,gBAAA,CACL,KAAK,gBAAA,CACL,KAAK,cACL,KAAK,eAAA,CACL,KAAK,iBAAA,CACD,OAAO,IAAA,CAAK,2BAAA,CAA4BA,EAAM,IAAA,CAAK,MAAuB,EAC9E,QACI,OAAO,CAAE,MAAA,CAAQ,eAAgB,CACzC,CACJ,CACJ,CAAA,CAEOC,EAAQ5B,CAAAA,CCxQf,IAAO6B,CAAAA,CAAQC,cAAAA,CAAeC,QAAQ,OAAA,CAAS,CAC3C,SAAU,CAACH,CAA4B,CAC3C,CAAC","file":"index.js","sourcesContent":["import { BigNumberInput } from '@medusajs/framework/types'\nimport { BigNumber, MathBN } from '@medusajs/framework/utils'\n\nfunction getCurrencyMultiplier(currency) {\n const currencyMultipliers = {\n 0: [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF'\n ],\n 3: ['BHD', 'IQD', 'JOD', 'KWD', 'OMR', 'TND']\n }\n\n currency = currency.toUpperCase()\n let power = 2\n for (const [key, value] of Object.entries(currencyMultipliers)) {\n if (value.includes(currency)) {\n power = parseInt(key, 10)\n break\n }\n }\n return Math.pow(10, power)\n}\n\n/**\n * Converts an amount to the format required by Stripe based on currency.\n * https://docs.stripe.com/currencies\n * @param {BigNumberInput} amount - The amount to be converted.\n * @param {string} currency - The currency code (e.g., 'USD', 'JOD').\n * @returns {number} - The converted amount in the smallest currency unit.\n */\nexport function getSmallestUnit(\n amount: BigNumberInput,\n currency: string\n): number {\n const multiplier = getCurrencyMultiplier(currency)\n\n const amount_ =\n Math.round(new BigNumber(MathBN.mult(amount, multiplier)).numeric) /\n multiplier\n\n const smallestAmount = new BigNumber(MathBN.mult(amount_, multiplier))\n\n let numeric = smallestAmount.numeric\n // Check if the currency requires rounding to the nearest ten\n if (multiplier === 1e3) {\n numeric = Math.ceil(numeric / 10) * 10\n }\n\n return parseInt(numeric.toString().split('.').shift()!, 10)\n}\n\n/**\n * Converts an amount from the smallest currency unit to the standard unit based on currency.\n * @param {BigNumberInput} amount - The amount in the smallest currency unit.\n * @param {string} currency - The currency code (e.g., 'USD', 'JOD').\n * @returns {number} - The converted amount in the standard currency unit.\n */\nexport function getAmountFromSmallestUnit(\n amount: BigNumberInput,\n currency: string\n): number {\n const multiplier = getCurrencyMultiplier(currency)\n const standardAmount = new BigNumber(MathBN.div(amount, multiplier))\n return standardAmount.numeric\n}","import { isPresent, MedusaError } from \"@medusajs/framework/utils\"\nimport {\n CreateOnboardingInput,\n CreateOnboardingResponse,\n CreatePayoutAccountInput,\n CreatePayoutAccountResponse,\n CreatePayoutInput,\n CreatePayoutResponse,\n IPayoutProvider,\n PayoutAccountStatus,\n PayoutStatus,\n PayoutWebhookActionInput,\n PayoutWebhookResult,\n} from \"@mercurjs/types\"\nimport { StripeConnectOptions } from \"@types\"\nimport { getSmallestUnit } from \"@utils\"\nimport Stripe from \"stripe\"\n\nconst DEFAULT_ACCOUNT_VALIDATION = {\n detailsSubmitted: true,\n chargesEnabled: true,\n payoutsEnabled: true,\n noOutstandingRequirements: true,\n requiredCapabilities: [],\n}\n\nclass StripeConnectProviderService implements IPayoutProvider {\n static identifier = \"stripe-connect\"\n protected readonly stripe_: Stripe\n protected readonly config_: StripeConnectOptions\n\n constructor(\n _cradle: Record<string, unknown>,\n options: StripeConnectOptions\n ) {\n this.config_ = options\n this.stripe_ = new Stripe(options.apiKey)\n }\n\n protected normalizePayoutParameters(\n extra: Record<string, unknown>\n ): Partial<Stripe.TransferCreateParams> & { destination: string } {\n const res = {\n } as Partial<Stripe.TransferCreateParams>\n\n res.destination = extra!.id as string\n res.source_transaction = extra?.source_transaction as string | undefined\n res.transfer_group = extra?.order_id as string | undefined\n res.description = extra?.description as string | undefined\n res.metadata = extra?.metadata as Stripe.MetadataParam | undefined\n\n\n return res as Partial<Stripe.TransferCreateParams> & { destination: string }\n }\n\n private getWebhookResultFromAccount_(\n account: Stripe.Account\n ): PayoutWebhookResult {\n const validation = {\n ...DEFAULT_ACCOUNT_VALIDATION,\n ...this.config_.accountValidation,\n }\n const requirements = account.requirements\n const disabledReason = requirements?.disabled_reason\n const hasOutstandingRequirements = Boolean(\n requirements?.currently_due?.length ||\n requirements?.past_due?.length ||\n requirements?.pending_verification?.length\n )\n const requiredCapabilities = validation.requiredCapabilities ?? []\n const hasInactiveCapabilities = requiredCapabilities.some((capability) => {\n return account.capabilities?.[capability as keyof Stripe.Account.Capabilities] !== \"active\"\n })\n\n if (disabledReason?.startsWith(\"rejected.\")) {\n return {\n action: \"account.rejected\",\n data: {\n id: account.id,\n },\n }\n }\n\n if (\n (!validation.detailsSubmitted || account.details_submitted) &&\n (!validation.chargesEnabled || account.charges_enabled) &&\n (!validation.payoutsEnabled || account.payouts_enabled) &&\n (!validation.noOutstandingRequirements || !hasOutstandingRequirements) &&\n !hasInactiveCapabilities\n ) {\n return {\n action: \"account.activated\",\n data: {\n id: account.id,\n },\n }\n }\n\n if (disabledReason) {\n return {\n action: \"account.restricted\",\n data: {\n id: account.id,\n },\n }\n }\n\n return {\n action: \"account.restricted\",\n data: {\n id: account.id,\n },\n }\n }\n\n private getWebhookResultFromPayout_(\n payout: Stripe.Payout\n ): PayoutWebhookResult {\n const payoutId = payout.metadata?.payout_id || payout.id\n\n switch (payout.status) {\n case \"pending\":\n case \"in_transit\":\n return {\n action: \"payout.processing\",\n data: {\n id: payoutId,\n },\n }\n case \"paid\":\n return {\n action: \"payout.paid\",\n data: {\n id: payoutId,\n },\n }\n case \"failed\":\n return {\n action: \"payout.failed\",\n data: {\n id: payoutId,\n },\n }\n case \"canceled\":\n return {\n action: \"payout.canceled\",\n data: {\n id: payoutId,\n },\n }\n default:\n return {\n action: \"not_supported\",\n }\n }\n }\n\n async createPayoutAccount(\n input: CreatePayoutAccountInput\n ): Promise<CreatePayoutAccountResponse> {\n const { data } = input;\n const country = data?.country as string\n\n if (!isPresent(country)) {\n throw new MedusaError(\n MedusaError.Types.INVALID_DATA,\n `\"country\" is required`\n );\n }\n\n const response = await this.stripe_.accounts.create({\n type: 'express',\n country,\n }, {\n idempotencyKey: input.context?.idempotency_key\n })\n\n return {\n id: response.id,\n status: PayoutAccountStatus.PENDING,\n data: response as unknown as Record<string, unknown>\n }\n }\n\n async createPayout(input: CreatePayoutInput): Promise<CreatePayoutResponse> {\n const normalizedInput = this.normalizePayoutParameters(input.data!)\n const transfer = await this.stripe_.transfers.create(\n {\n currency: input.currency_code,\n amount: getSmallestUnit(input.amount, input.currency_code),\n ...normalizedInput,\n },\n { idempotencyKey: input.context?.idempotency_key }\n );\n\n\n return {\n data: transfer as unknown as Record<string, unknown>,\n status: PayoutStatus.PENDING\n }\n }\n\n async createOnboarding(\n input: CreateOnboardingInput\n ): Promise<CreateOnboardingResponse> {\n const id = input?.data?.id as string\n if (!isPresent(id)) {\n throw new MedusaError(\n MedusaError.Types.INVALID_DATA,\n `'id' is required`\n );\n }\n\n if (!isPresent(input.data?.refresh_url)) {\n throw new MedusaError(\n MedusaError.Types.INVALID_DATA,\n `'refresh_url' is required`\n );\n }\n\n if (!isPresent(input.data?.return_url)) {\n throw new MedusaError(\n MedusaError.Types.INVALID_DATA,\n `'return_url' is required`\n );\n }\n\n const accountLink = await this.stripe_.accountLinks.create({\n account: id,\n refresh_url: input.data?.refresh_url as string,\n return_url: input.data?.return_url as string,\n type: \"account_onboarding\",\n }, {\n idempotencyKey: input.context?.idempotency_key\n });\n\n return {\n data: accountLink as unknown as Record<string, unknown>,\n };\n }\n\n async getWebhookActionAndData(\n payload: PayoutWebhookActionInput\n ): Promise<PayoutWebhookResult> {\n const signature = payload.headers[\"stripe-signature\"] as string\n\n const event = this.stripe_.webhooks.constructEvent(\n payload.rawData as string | Buffer,\n signature,\n this.config_.webhookSecret\n )\n\n switch (event.type) {\n case \"account.updated\":\n return this.getWebhookResultFromAccount_(event.data.object as Stripe.Account)\n case \"payout.created\":\n case \"payout.updated\":\n case \"payout.paid\":\n case \"payout.failed\":\n case \"payout.canceled\":\n return this.getWebhookResultFromPayout_(event.data.object as Stripe.Payout)\n default:\n return { action: \"not_supported\" }\n }\n }\n}\n\nexport default StripeConnectProviderService\n","import { ModuleProvider, Modules } from \"@medusajs/framework/utils\"\nimport StripeConnectProviderService from \"./services/stripe-connect\"\n\nexport default ModuleProvider(Modules.PAYMENT, {\n services: [StripeConnectProviderService],\n})"]}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@mercurjs/payout-stripe-connect",
3
+ "version": "2.0.0-canary.101",
4
+ "description": "Stripe Connect payment provider for Mercur",
5
+ "private": false,
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/mercurjs/mercur",
10
+ "directory": "packages/providers/payout-stripe-connect"
11
+ },
12
+ "engines": {
13
+ "node": ">=20"
14
+ },
15
+ "author": "Medusa",
16
+ "license": "MIT",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "exports": {
21
+ ".": "./dist/index.js"
22
+ },
23
+ "scripts": {
24
+ "dev": "tsup --watch",
25
+ "build": "tsup"
26
+ },
27
+ "peerDependencies": {
28
+ "@medusajs/framework": "2.13.4"
29
+ },
30
+ "devDependencies": {
31
+ "@medusajs/framework": "2.13.4",
32
+ "@mercurjs/types": "2.0.0-canary.101",
33
+ "tsup": "^8.5.0"
34
+ },
35
+ "dependencies": {
36
+ "stripe": "^15.5.0"
37
+ },
38
+ "keywords": [
39
+ "medusa-plugin",
40
+ "medusa-plugin-payment",
41
+ "stripe-connect"
42
+ ]
43
+ }