@rebilly/instruments 16.112.1 → 16.113.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
- ## [16.112.1](https://github.com/Rebilly/rebilly/compare/instruments/core-v16.112.0...instruments/core-v16.112.1) (2026-05-12)
1
+ ## [16.113.0](https://github.com/Rebilly/rebilly/compare/instruments/core-v16.112.1...instruments/core-v16.113.0) (2026-05-13)
2
2
 
3
3
 
4
- ### Bug Fixes
4
+ ### Features
5
5
 
6
- * **storefront-payment-form:** Payout request did not require address in instruments config ([#21355](https://github.com/Rebilly/rebilly/issues/21355)) ([2194f00](https://github.com/Rebilly/rebilly/commit/2194f00512f4a7f398e1221fd44c2fb7ca277bd7))
6
+ * **instruments:** setup vegawallet instruments during payout ([#21383](https://github.com/Rebilly/rebilly/issues/21383)) ([ac81521](https://github.com/Rebilly/rebilly/commit/ac81521a3c4cb5abf9cffa15bf53a9c6a78a362c))
package/dist/index.js CHANGED
@@ -2206,7 +2206,7 @@ let ModalIframe$1 = class ModalIframe extends BaseIframe {
2206
2206
  window.addEventListener(
2207
2207
  "message",
2208
2208
  async (event) => {
2209
- var _a, _b;
2209
+ var _a, _b, _c;
2210
2210
  if (((_a = event.data) == null ? void 0 : _a.type) === "rebilly-spf:ready" && event.source === this.component.frame.contentWindow) {
2211
2211
  this.component.frame.contentWindow.postMessage(
2212
2212
  {
@@ -2223,7 +2223,19 @@ let ModalIframe$1 = class ModalIframe extends BaseIframe {
2223
2223
  isRedirected = true;
2224
2224
  }
2225
2225
  if (event.data === "rebilly-instruments-approval-url-close") {
2226
- if (state.options.transactionType === "purchase") {
2226
+ if ((_b = this.model) == null ? void 0 : _b.setup) {
2227
+ const { instrument, transaction } = this.model.setup;
2228
+ state.storefront.setSessionToken(
2229
+ instrument.token || state.options.jwt
2230
+ );
2231
+ const { fields: updatedTransaction } = await state.storefront.transactions.get({
2232
+ id: transaction.id
2233
+ });
2234
+ close({
2235
+ transaction: updatedTransaction,
2236
+ instrument
2237
+ });
2238
+ } else if (state.options.transactionType === "purchase") {
2227
2239
  state.storefront.setSessionToken(
2228
2240
  state.data.token || state.options.jwt
2229
2241
  );
@@ -2231,7 +2243,7 @@ let ModalIframe$1 = class ModalIframe extends BaseIframe {
2231
2243
  state.storefront.transactions.get({
2232
2244
  id: state.data.transaction.id
2233
2245
  }),
2234
- ((_b = state.data.invoice) == null ? void 0 : _b.id) ? state.storefront.invoices.get({
2246
+ ((_c = state.data.invoice) == null ? void 0 : _c.id) ? state.storefront.invoices.get({
2235
2247
  id: state.data.invoice.id
2236
2248
  }) : { fields: null }
2237
2249
  ]);
@@ -2244,17 +2256,6 @@ let ModalIframe$1 = class ModalIframe extends BaseIframe {
2244
2256
  updatedPurchase.invoice = invoice;
2245
2257
  }
2246
2258
  close(updatedPurchase);
2247
- } else if (state.options.transactionType === "setup") {
2248
- state.storefront.setSessionToken(
2249
- state.data.instrument.token || state.options.jwt
2250
- );
2251
- const { fields: transaction } = await state.storefront.transactions.get({
2252
- id: state.data.transaction.id
2253
- });
2254
- close({
2255
- transaction,
2256
- instrument: state.data.instrument
2257
- });
2258
2259
  } else {
2259
2260
  close();
2260
2261
  }
@@ -5298,7 +5299,7 @@ function C$1({ options: e2 }) {
5298
5299
  }
5299
5300
  function o2() {
5300
5301
  const i = {
5301
- "REB-API-CONSUMER": `${["Rebilly", e2.appName, "js-sdk"].filter((g) => g).join("/")}@8ea67b3`
5302
+ "REB-API-CONSUMER": `${["Rebilly", e2.appName, "js-sdk"].filter((g) => g).join("/")}@ac81521`
5302
5303
  };
5303
5304
  return e2.apiKey && (i["REB-APIKEY"] = e2.apiKey), i;
5304
5305
  }
@@ -18720,16 +18721,19 @@ async function fetchAccountAndWebsite() {
18720
18721
  });
18721
18722
  }
18722
18723
  async function setupPaymentInstrument({
18723
- data
18724
+ data,
18725
+ instrument
18724
18726
  }) {
18725
18727
  return Endpoint(async () => {
18726
18728
  var _a, _b, _c;
18727
18729
  validateStorefront(state.storefront);
18728
18730
  validateOptions$1(state.options);
18729
- const { fields: instrument } = await state.storefront.paymentInstruments.create({ data });
18730
- state.storefront.setSessionToken(instrument.token || state.options.jwt);
18731
+ const targetInstrument = instrument ?? (await state.storefront.paymentInstruments.create({ data })).fields;
18732
+ state.storefront.setSessionToken(
18733
+ targetInstrument.token || state.options.jwt
18734
+ );
18731
18735
  const setupPayload = {
18732
- id: instrument.id,
18736
+ id: targetInstrument.id,
18733
18737
  data: {
18734
18738
  websiteId: state.options.websiteId,
18735
18739
  ...data
@@ -18745,7 +18749,7 @@ async function setupPaymentInstrument({
18745
18749
  setupPayload.data.redirectUrl = `${setupPayload.data.redirectUrl}&originalRedirectUrl=${state.data.transaction.redirectUrl}`;
18746
18750
  }
18747
18751
  const { fields: transaction } = await state.storefront.paymentInstruments.setup(setupPayload);
18748
- return { instrument, transaction };
18752
+ return { instrument: targetInstrument, transaction };
18749
18753
  });
18750
18754
  }
18751
18755
  async function fetchPaymentInstrument() {
@@ -18897,6 +18901,9 @@ class DataInstance {
18897
18901
  } else if (this.transaction) {
18898
18902
  currency = this.transaction.currency;
18899
18903
  amount = this.transaction.amount;
18904
+ } else if (this.payout) {
18905
+ currency = this.payout.currency;
18906
+ amount = this.payout.amount;
18900
18907
  } else if (this.money) {
18901
18908
  currency = this.money.currency;
18902
18909
  amount = this.money.amount;
@@ -23107,25 +23114,78 @@ async function makePayment({ payload }) {
23107
23114
  }
23108
23115
  return fields;
23109
23116
  }
23110
- async function makePayout({
23111
- payload: {
23112
- isExistingInstrument,
23113
- _raw: { id: paymentInstrumentId }
23114
- }
23117
+ const PAYOUT_SETUP_REQUIRED_METHODS = ["VegaWallet"];
23118
+ async function awaitPayoutSetupApprovalUrl({
23119
+ instrument,
23120
+ transaction
23115
23121
  }) {
23116
- if (!isExistingInstrument) {
23117
- const { id: newPaymentInstrumentId } = await createPaymentInstrument({
23118
- data: { token: paymentInstrumentId }
23122
+ var _a, _b;
23123
+ if (!(transaction == null ? void 0 : transaction.approvalUrl) || transaction.result !== "unknown") {
23124
+ return;
23125
+ }
23126
+ validateOptions$1(state.options);
23127
+ if ((_a = state.options.features) == null ? void 0 : _a.fullPageRedirect) {
23128
+ window.location.href = transaction.approvalUrl;
23129
+ return new Promise(() => {
23119
23130
  });
23120
- paymentInstrumentId = newPaymentInstrumentId;
23121
23131
  }
23122
- const payoutRequest = await updatePayoutRequest({
23132
+ const paymentMethodsUrl = (_b = state.options._computed) == null ? void 0 : _b.paymentMethodsUrl;
23133
+ const name = "rebilly-instruments-approval-url";
23134
+ return new Promise((resolve, reject) => {
23135
+ mountModal({
23136
+ name,
23137
+ // Load the iframe at the root URL so App.vue can complete its postmate
23138
+ // handshake before mountModal navigates the child router to the approval-url route
23139
+ url: `${paymentMethodsUrl}?name=${name}`,
23140
+ model: {
23141
+ setup: { instrument, transaction }
23142
+ },
23143
+ close: ({
23144
+ transaction: updatedTransaction
23145
+ } = {}) => {
23146
+ if ((updatedTransaction == null ? void 0 : updatedTransaction.result) === "declined") {
23147
+ reject(
23148
+ new Error("Payment instrument verification failed.")
23149
+ );
23150
+ return;
23151
+ }
23152
+ resolve();
23153
+ }
23154
+ });
23155
+ });
23156
+ }
23157
+ async function makePayout({ payload }) {
23158
+ const { isExistingInstrument, _raw, redirectUrl } = payload;
23159
+ const paymentInstrumentId = await resolvePaymentInstrumentId({
23160
+ token: _raw,
23161
+ isExistingInstrument,
23162
+ redirectUrl
23163
+ });
23164
+ return updatePayoutRequest({
23123
23165
  id: state.data.payout.id,
23124
- data: {
23125
- paymentInstrumentId
23126
- }
23166
+ data: { paymentInstrumentId }
23167
+ });
23168
+ }
23169
+ async function resolvePaymentInstrumentId({
23170
+ token,
23171
+ isExistingInstrument,
23172
+ redirectUrl
23173
+ }) {
23174
+ if (PAYOUT_SETUP_REQUIRED_METHODS.includes(token.method)) {
23175
+ const redirectField = redirectUrl ? { redirectUrl } : {};
23176
+ const { instrument, transaction } = await setupPaymentInstrument(
23177
+ isExistingInstrument ? { instrument: token, data: redirectField } : { data: { token: token.id, ...redirectField } }
23178
+ );
23179
+ await awaitPayoutSetupApprovalUrl({ instrument, transaction });
23180
+ return instrument.id;
23181
+ }
23182
+ if (isExistingInstrument) {
23183
+ return token.id;
23184
+ }
23185
+ const { id } = await createPaymentInstrument({
23186
+ data: { token: token.id }
23127
23187
  });
23128
- return payoutRequest;
23188
+ return id;
23129
23189
  }
23130
23190
  async function purchase({ payload }) {
23131
23191
  var _a, _b;
@@ -23196,11 +23256,14 @@ async function setup({ payload }) {
23196
23256
  window.location = transaction.approvalUrl;
23197
23257
  } else {
23198
23258
  const { paymentMethodsUrl } = state.options._computed;
23259
+ const name = "rebilly-instruments-approval-url";
23199
23260
  mountModal({
23200
- name: "rebilly-instruments-approval-url",
23201
- url: `${paymentMethodsUrl}/approval-url`,
23261
+ name,
23262
+ // Load the iframe at the root URL so App.vue can complete its postmate
23263
+ // handshake before mountModal navigates the child router to the approval-url route
23264
+ url: `${paymentMethodsUrl}?name=${name}`,
23202
23265
  model: {
23203
- setup: { transaction }
23266
+ setup: { instrument, transaction }
23204
23267
  },
23205
23268
  close: ({
23206
23269
  transaction: updatedTransaction = transaction