@stacksjs/payments 0.75.230 → 0.75.236

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.
@@ -77,7 +77,7 @@ export declare function checkoutLineItemsTotal(lineItems: readonly Stripe.Checko
77
77
  * splitFee(-101, { tip: 2, planet: 1 }) // { tip: -67, planet: -34 }
78
78
  * splitFee(50, { tip: 0, planet: 0 }) // { tip: 50, planet: 0 }
79
79
  */
80
- export declare function splitFee<K extends string>(amount: number, weights: Readonly<Record<K, number>>, fallback?: K): Record<K, number>;
80
+ export declare function splitFee<K extends string>(amount: number, weights: Readonly<Record<K, number>>, fallback?: NoInfer<K>): Record<K, number>;
81
81
  export declare interface DestinationOptions {
82
82
  destination: string
83
83
  feePercent?: number
@@ -27,7 +27,11 @@ export declare function connectRefundParams(source: RefundSource, options?: Conn
27
27
  * Pass a deterministic `idempotencyKey` (your refund row's id, say) so a
28
28
  * retried request cannot refund twice; without one each call is a new refund.
29
29
  */
30
- export declare function connectRefund(paymentId: string, options?: ConnectRefundOptions & { idempotencyKey?: string }): Promise<Stripe.Response<Stripe.Refund>>;
30
+ export declare function connectRefund(paymentId: string, options?: ConnectRefundOptions & {
31
+ idempotencyKey?: string
32
+
33
+ client?: Pick<Stripe, 'paymentIntents' | 'charges' | 'refunds'>
34
+ }): Promise<Stripe.Response<Stripe.Refund>>;
31
35
  /**
32
36
  * Refunds that know about Connect.
33
37
  *
@@ -1 +1 @@
1
- import{stripe}from"../drivers/stripe";import{freshIdempotencyKey}from"../idempotency";function expandedCharge(source){return source.latest_charge&&typeof source.latest_charge==="object"?source.latest_charge:null}export function isDestinationCharge(source){if(!source)return!1;const charge=expandedCharge(source);return Boolean(source.transfer_data?.destination||source.transfer||charge?.transfer_data?.destination||charge?.transfer)}export function tookApplicationFee(source){if(!source)return!1;const charge=expandedCharge(source);return Boolean((source.application_fee_amount??0)>0||source.application_fee||(charge?.application_fee_amount??0)>0||charge?.application_fee)}export function connectRefundParams(source,options={}){if(!source?.id||typeof source.id!=="string")throw Error("[payments/connect] connectRefundParams needs the PaymentIntent or Charge to refund");if(options.amount!=null&&(!Number.isSafeInteger(options.amount)||options.amount<=0))throw Error(`[payments/connect] a refund amount is a positive whole number of minor units, got ${options.amount}`);const isIntent=source.object==="payment_intent"||source.id.startsWith("pi_"),destination=isDestinationCharge(source),reverse=destination&&(options.reverseTransfer??!0),refundFee=destination&&tookApplicationFee(source)&&(options.refundApplicationFee??!0);return{...isIntent?{payment_intent:source.id}:{charge:source.id},...options.amount!=null?{amount:options.amount}:{},...options.reason?{reason:options.reason}:{},...options.metadata?{metadata:options.metadata}:{},...reverse?{reverse_transfer:!0}:{},...refundFee?{refund_application_fee:!0}:{}}}export async function connectRefund(paymentId,options={}){if(!paymentId||typeof paymentId!=="string")throw Error("[payments/connect] connectRefund needs a PaymentIntent or Charge id");const{idempotencyKey,...refundOptions}=options,source=paymentId.startsWith("pi_")?await stripe.paymentIntents.retrieve(paymentId,{expand:["latest_charge"]}):await stripe.charges.retrieve(paymentId);return await stripe.refunds.create(connectRefundParams(source,refundOptions),{idempotencyKey:idempotencyKey??freshIdempotencyKey("connect.refund",paymentId,refundOptions.amount??"full")})}
1
+ import{stripe}from"../drivers/stripe";import{freshIdempotencyKey}from"../idempotency";function expandedCharge(source){return source.latest_charge&&typeof source.latest_charge==="object"?source.latest_charge:null}export function isDestinationCharge(source){if(!source)return!1;const charge=expandedCharge(source);return Boolean(source.transfer_data?.destination||source.transfer||charge?.transfer_data?.destination||charge?.transfer)}export function tookApplicationFee(source){if(!source)return!1;const charge=expandedCharge(source);return Boolean((source.application_fee_amount??0)>0||source.application_fee||(charge?.application_fee_amount??0)>0||charge?.application_fee)}export function connectRefundParams(source,options={}){if(!source?.id||typeof source.id!=="string")throw Error("[payments/connect] connectRefundParams needs the PaymentIntent or Charge to refund");if(options.amount!=null&&(!Number.isSafeInteger(options.amount)||options.amount<=0))throw Error(`[payments/connect] a refund amount is a positive whole number of minor units, got ${options.amount}`);const isIntent=source.object==="payment_intent"||source.id.startsWith("pi_"),destination=isDestinationCharge(source),reverse=destination&&(options.reverseTransfer??!0),refundFee=destination&&tookApplicationFee(source)&&(options.refundApplicationFee??!0);return{...isIntent?{payment_intent:source.id}:{charge:source.id},...options.amount!=null?{amount:options.amount}:{},...options.reason?{reason:options.reason}:{},...options.metadata?{metadata:options.metadata}:{},...reverse?{reverse_transfer:!0}:{},...refundFee?{refund_application_fee:!0}:{}}}export async function connectRefund(paymentId,options={}){if(!paymentId||typeof paymentId!=="string")throw Error("[payments/connect] connectRefund needs a PaymentIntent or Charge id");const{idempotencyKey,client=stripe,...refundOptions}=options,source=paymentId.startsWith("pi_")?await client.paymentIntents.retrieve(paymentId,{expand:["latest_charge"]}):await client.charges.retrieve(paymentId);return await client.refunds.create(connectRefundParams(source,refundOptions),{idempotencyKey:idempotencyKey??freshIdempotencyKey("connect.refund",paymentId,refundOptions.amount??"full")})}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/payments",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.230",
5
+ "version": "0.75.236",
6
6
  "description": "The Stacks payments package. Currently supporting Stripe.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -60,12 +60,12 @@
60
60
  "prepublishOnly": "bun run build"
61
61
  },
62
62
  "dependencies": {
63
- "@stacksjs/config": "0.75.230",
64
- "@stacksjs/database": "0.75.230",
65
- "@stacksjs/error-handling": "0.75.230",
66
- "@stacksjs/logging": "0.75.230",
67
- "@stacksjs/orm": "0.75.230",
68
- "@stacksjs/types": "0.75.230"
63
+ "@stacksjs/config": "0.75.236",
64
+ "@stacksjs/database": "0.75.236",
65
+ "@stacksjs/error-handling": "0.75.236",
66
+ "@stacksjs/logging": "0.75.236",
67
+ "@stacksjs/orm": "0.75.236",
68
+ "@stacksjs/types": "0.75.236"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "@stripe/stripe-js": "^10.0.0",
@@ -80,7 +80,7 @@
80
80
  }
81
81
  },
82
82
  "devDependencies": {
83
- "@stacksjs/utils": "0.75.230",
83
+ "@stacksjs/utils": "0.75.236",
84
84
  "@stripe/stripe-js": "^10.0.0",
85
85
  "better-dx": "^0.2.24",
86
86
  "stripe": "23.0.0"