@rebilly/instruments 3.28.3 → 3.28.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebilly/instruments",
3
- "version": "3.28.3",
3
+ "version": "3.28.5",
4
4
  "author": "Rebilly",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -3,18 +3,52 @@ import { Endpoint } from './index';
3
3
 
4
4
  export async function postPurchase({ data }) {
5
5
  return Endpoint(async () => {
6
- if (data._raw) {
7
- delete data._raw;
8
- }
9
- return state.storefront.purchase.purchase({ data });
6
+ // https://storefront-api-docs.rebilly.com/tag/Purchases/operation/StorefrontPostPurchase
7
+ const purchaseSchemaKeys = [
8
+ 'websiteId',
9
+ 'paymentInstruction',
10
+ 'items',
11
+ 'billingAddress',
12
+ 'deliveryAddress',
13
+ 'shippingRateId',
14
+ 'couponIds',
15
+ 'password',
16
+ 'redirectUrl',
17
+ ];
18
+ Object.keys(data).forEach((key) => {
19
+ if (!purchaseSchemaKeys.includes(key)) {
20
+ delete data[key];
21
+ }
22
+ });
23
+ return state.storefront.purchase.purchase({data});
10
24
  });
11
25
  }
12
26
 
13
27
  export async function postPayment({ data }) {
14
28
  return Endpoint(async () => {
15
- if (data._raw) {
16
- delete data._raw;
29
+ const {token, transactionId, invoiceId, websiteId, paymentInstrumentId} = data;
30
+ // https://storefront-api-docs.rebilly.com/tag/Purchases/operation/StorefrontPostPayment
31
+ const purchaseSchemaKeys = ['riskMetadata', 'redirectUrl'];
32
+ if (token) {
33
+ purchaseSchemaKeys.push('token');
34
+ }
35
+ if (paymentInstrumentId) {
36
+ purchaseSchemaKeys.push('paymentInstrumentId');
37
+ }
38
+ if (transactionId) {
39
+ purchaseSchemaKeys.push('transactionId');
17
40
  }
18
- return state.storefront.purchase.payment({ data });
41
+ if (invoiceId) {
42
+ purchaseSchemaKeys.push('invoiceId');
43
+ }
44
+ if (websiteId) {
45
+ purchaseSchemaKeys.push('amount', 'currency', 'websiteId');
46
+ }
47
+ Object.keys(data).forEach((key) => {
48
+ if (!purchaseSchemaKeys.includes(key)) {
49
+ delete data[key];
50
+ }
51
+ });
52
+ return state.storefront.purchase.payment({data});
19
53
  });
20
- }
54
+ }