@moonpay/platform-sdk-react-native 1.31.1 → 1.32.0

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.
package/dist/index.d.cts CHANGED
@@ -147,6 +147,13 @@ interface SetupBuyButtonOptions {
147
147
  googlePayButtonSettings?: GooglePayFrame$1.GooglePayButtonSettings;
148
148
  /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
149
149
  presentation?: PresentationMode;
150
+ /**
151
+ * The link back to your app after the customer finishes in another app that
152
+ * the payment method opens (for example Cash App), such as
153
+ * `myapp://moonpay-return`. Without it the customer switches back to your
154
+ * app themselves.
155
+ */
156
+ linkReturnUrl?: string;
150
157
  /**
151
158
  * Run the frame hidden, with no button: it processes the quote on load, the
152
159
  * way the deprecated `setupBuy` did.
@@ -429,6 +436,13 @@ interface MoonPayBuyButtonProps {
429
436
  applePayButtonSettings?: ApplePayFrame$1.ApplePayButtonSettings;
430
437
  /** Styling for the Google Pay button variant. Passed through to the frame, which is authoritative. Ignored when `headless` is set. Mount-time only. */
431
438
  googlePayButtonSettings?: GooglePayFrame$1.GooglePayButtonSettings;
439
+ /**
440
+ * The link back to your app after the customer finishes in another app that
441
+ * the payment method opens (for example Cash App), such as
442
+ * `myapp://moonpay-return`. Without it the customer switches back to your
443
+ * app themselves. Mount-time only.
444
+ */
445
+ linkReturnUrl?: string;
432
446
  /**
433
447
  * Render nothing visible and process the quote on load, the way the
434
448
  * deprecated `<MoonPayBuyFrame>` did. Mount-time only.
@@ -442,7 +456,7 @@ interface MoonPayBuyButtonProps {
442
456
  webViewProps?: Partial<WebViewProps>;
443
457
  }
444
458
  /** Inline card/buy button. Render it wherever it should appear in your layout. */
445
- declare function MoonPayBuyButton({ quote, externalTransactionId, applePayButtonSettings, googlePayButtonSettings, headless, onEvent, style, webViewProps, }: MoonPayBuyButtonProps): JSX.Element;
459
+ declare function MoonPayBuyButton({ quote, externalTransactionId, applePayButtonSettings, googlePayButtonSettings, linkReturnUrl, headless, onEvent, style, webViewProps, }: MoonPayBuyButtonProps): JSX.Element;
446
460
 
447
461
  interface MoonPayBuyFrameProps {
448
462
  /** Quote signature from getQuote(). Reactive — updates are pushed via setQuote without remounting. */
package/dist/index.d.ts CHANGED
@@ -147,6 +147,13 @@ interface SetupBuyButtonOptions {
147
147
  googlePayButtonSettings?: GooglePayFrame$1.GooglePayButtonSettings;
148
148
  /** Frame chrome. Defaults to the frame's own default (bare) when omitted. */
149
149
  presentation?: PresentationMode;
150
+ /**
151
+ * The link back to your app after the customer finishes in another app that
152
+ * the payment method opens (for example Cash App), such as
153
+ * `myapp://moonpay-return`. Without it the customer switches back to your
154
+ * app themselves.
155
+ */
156
+ linkReturnUrl?: string;
150
157
  /**
151
158
  * Run the frame hidden, with no button: it processes the quote on load, the
152
159
  * way the deprecated `setupBuy` did.
@@ -429,6 +436,13 @@ interface MoonPayBuyButtonProps {
429
436
  applePayButtonSettings?: ApplePayFrame$1.ApplePayButtonSettings;
430
437
  /** Styling for the Google Pay button variant. Passed through to the frame, which is authoritative. Ignored when `headless` is set. Mount-time only. */
431
438
  googlePayButtonSettings?: GooglePayFrame$1.GooglePayButtonSettings;
439
+ /**
440
+ * The link back to your app after the customer finishes in another app that
441
+ * the payment method opens (for example Cash App), such as
442
+ * `myapp://moonpay-return`. Without it the customer switches back to your
443
+ * app themselves. Mount-time only.
444
+ */
445
+ linkReturnUrl?: string;
432
446
  /**
433
447
  * Render nothing visible and process the quote on load, the way the
434
448
  * deprecated `<MoonPayBuyFrame>` did. Mount-time only.
@@ -442,7 +456,7 @@ interface MoonPayBuyButtonProps {
442
456
  webViewProps?: Partial<WebViewProps>;
443
457
  }
444
458
  /** Inline card/buy button. Render it wherever it should appear in your layout. */
445
- declare function MoonPayBuyButton({ quote, externalTransactionId, applePayButtonSettings, googlePayButtonSettings, headless, onEvent, style, webViewProps, }: MoonPayBuyButtonProps): JSX.Element;
459
+ declare function MoonPayBuyButton({ quote, externalTransactionId, applePayButtonSettings, googlePayButtonSettings, linkReturnUrl, headless, onEvent, style, webViewProps, }: MoonPayBuyButtonProps): JSX.Element;
446
460
 
447
461
  interface MoonPayBuyFrameProps {
448
462
  /** Quote signature from getQuote(). Reactive — updates are pushed via setQuote without remounting. */
package/dist/index.js CHANGED
@@ -16,6 +16,17 @@ import {
16
16
  presentationParams,
17
17
  themeParams
18
18
  } from "@moonpay/platform-sdk-core";
19
+
20
+ // src/return-url.ts
21
+ var MAX_URL_LENGTH = 2048;
22
+ var UNSAFE_RETURN_URL_SCHEMES = /* @__PURE__ */ new Set(["javascript", "data", "file", "vbscript", "blob"]);
23
+ function isValidReturnUrl(value) {
24
+ if (typeof value !== "string" || value.length > MAX_URL_LENGTH) return false;
25
+ const scheme = /^([a-z][a-z0-9+.-]*):\S+$/i.exec(value)?.[1];
26
+ return scheme !== void 0 && !UNSAFE_RETURN_URL_SCHEMES.has(scheme.toLowerCase());
27
+ }
28
+
29
+ // src/frame-specs.ts
19
30
  function createQuoteCommands(send, channelId) {
20
31
  return {
21
32
  setQuote: (signature) => send({
@@ -125,12 +136,11 @@ var googlePaySpec = {
125
136
  },
126
137
  errorEvent: (message) => ({ kind: "error", payload: { kind: "genericError", message } })
127
138
  };
128
- var buyButtonSpec = {
129
- channelPrefix: "buy-button",
130
- path: FRAME_PATHS.buyButton,
131
- enterprise: true,
132
- hidden: false,
133
- buildParams: (ctx, props) => ({
139
+ function buyButtonParams(ctx, props) {
140
+ if (props.linkReturnUrl !== void 0 && !isValidReturnUrl(props.linkReturnUrl)) {
141
+ throw new Error("linkReturnUrl must be an absolute URL, for example myapp://moonpay-return");
142
+ }
143
+ return {
134
144
  clientToken: ctx.core.context.clientToken,
135
145
  signature: props.quote,
136
146
  ...props.externalTransactionId && { externalTransactionId: props.externalTransactionId },
@@ -138,8 +148,16 @@ var buyButtonSpec = {
138
148
  ...props.googlePayButtonSettings && {
139
149
  googlePayButtonSettings: props.googlePayButtonSettings
140
150
  },
151
+ ...props.linkReturnUrl && { linkReturnUrl: props.linkReturnUrl },
141
152
  ...presentationParams(props.presentation)
142
- }),
153
+ };
154
+ }
155
+ var buyButtonSpec = {
156
+ channelPrefix: "buy-button",
157
+ path: FRAME_PATHS.buyButton,
158
+ enterprise: true,
159
+ hidden: false,
160
+ buildParams: (ctx, props) => buyButtonParams(ctx, props),
143
161
  createCommands: createQuoteCommands,
144
162
  reactiveProps: {
145
163
  quote: (commands, quote) => commands.setQuote(quote)
@@ -177,7 +195,7 @@ var headlessBuyButtonSpec = {
177
195
  ...buyButtonSpec,
178
196
  hidden: true,
179
197
  buildParams: (ctx, props) => ({
180
- ...buyButtonSpec.buildParams?.(ctx, props),
198
+ ...buyButtonParams(ctx, props),
181
199
  headless: true
182
200
  })
183
201
  };
@@ -831,7 +849,8 @@ async function setupBuyButton(deps, opts) {
831
849
  externalTransactionId: opts.externalTransactionId,
832
850
  applePayButtonSettings: opts.applePayButtonSettings,
833
851
  googlePayButtonSettings: opts.googlePayButtonSettings,
834
- presentation: opts.presentation
852
+ presentation: opts.presentation,
853
+ linkReturnUrl: opts.linkReturnUrl
835
854
  }
836
855
  );
837
856
  handle.onEvent((event) => opts.onEvent?.(event));
@@ -1586,6 +1605,7 @@ function MoonPayBuyButton({
1586
1605
  externalTransactionId,
1587
1606
  applePayButtonSettings,
1588
1607
  googlePayButtonSettings,
1608
+ linkReturnUrl,
1589
1609
  headless,
1590
1610
  onEvent,
1591
1611
  style,
@@ -1595,7 +1615,13 @@ function MoonPayBuyButton({
1595
1615
  MoonPayFrameView,
1596
1616
  {
1597
1617
  spec: headless ? headlessBuyButtonSpec : buyButtonSpec,
1598
- props: { quote, externalTransactionId, applePayButtonSettings, googlePayButtonSettings },
1618
+ props: {
1619
+ quote,
1620
+ externalTransactionId,
1621
+ applePayButtonSettings,
1622
+ googlePayButtonSettings,
1623
+ linkReturnUrl
1624
+ },
1599
1625
  style,
1600
1626
  defaultStyle: { height: 48 },
1601
1627
  onEvent,