@pintahub/shopify-api 2.3.0 → 2.3.1

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.
@@ -6,7 +6,6 @@ export interface GetOrderTransactionInput extends Record<string, any> {
6
6
  export interface GetOrderTransactionOutput extends Record<string, any> {
7
7
  }
8
8
  export declare class GetOrderTransaction extends ActionBuilder<AxiosInstance, GetOrderTransactionInput, GetOrderTransactionOutput> {
9
- private _parseFee;
10
9
  private _parsePaymentMethod;
11
10
  private _parseTransaction;
12
11
  run(args: GetOrderTransactionInput): Promise<GetOrderTransactionOutput>;
@@ -12,27 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.GetOrderTransaction = void 0;
13
13
  const ActionBuilder_1 = require("../../ActionBuilder");
14
14
  const parseOnlyId_1 = require("../../../utils/parseOnlyId");
15
+ const _parseFee_1 = require("./transactions/_parseFee");
15
16
  class GetOrderTransaction extends ActionBuilder_1.ActionBuilder {
16
- _parseFee(receipt, gateway) {
17
- console.log('receipt', receipt);
18
- if (gateway === 'shopify_payments') {
19
- const { metadata } = Object.assign({}, receipt);
20
- const { transaction_fee_total_amount } = Object.assign({}, metadata);
21
- if (!transaction_fee_total_amount)
22
- return null;
23
- const n = parseFloat(transaction_fee_total_amount);
24
- if (isNaN(n))
25
- return null;
26
- return n / 100;
27
- }
28
- const { fee_amount } = Object.assign({}, receipt);
29
- if (fee_amount) {
30
- const n = parseFloat(fee_amount);
31
- if (!isNaN(n))
32
- return n;
33
- }
34
- return null;
35
- }
36
17
  _parsePaymentMethod(transaction) {
37
18
  const { payment_details } = Object.assign({}, transaction);
38
19
  const { payment_method_name } = Object.assign({}, payment_details);
@@ -49,7 +30,7 @@ class GetOrderTransaction extends ActionBuilder_1.ActionBuilder {
49
30
  return {};
50
31
  }
51
32
  const { receipt, gateway, currency } = Object.assign({}, saleTransaction);
52
- const fee_amount = this._parseFee(receipt, gateway);
33
+ const fee_amount = (0, _parseFee_1._parseFee)(receipt, gateway);
53
34
  const paymentMethod = this._parsePaymentMethod(saleTransaction);
54
35
  return {
55
36
  gateway,
@@ -0,0 +1 @@
1
+ export declare const _parseFee: (receipt: any, gateway: string) => number | null;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._parseFee = void 0;
4
+ const _fromPurchaseUnits = (receipt) => {
5
+ const { purchase_units } = Object.assign({}, receipt);
6
+ if (!Array.isArray(purchase_units) || purchase_units.length === 0)
7
+ return null;
8
+ const pu = purchase_units[0];
9
+ if (!pu)
10
+ return null;
11
+ const { payment_instruction } = Object.assign({}, pu);
12
+ const { platform_fees } = Object.assign({}, payment_instruction);
13
+ const arr = Array.isArray(platform_fees) ? platform_fees : [];
14
+ if (arr.length === 0)
15
+ return null;
16
+ const [firstFee] = arr;
17
+ if (!firstFee)
18
+ return null;
19
+ const { amount } = Object.assign({}, firstFee);
20
+ const { value } = Object.assign({}, amount);
21
+ if (!value)
22
+ return null;
23
+ const n = parseFloat(value);
24
+ if (isNaN(n))
25
+ return null;
26
+ return n;
27
+ };
28
+ const _parseFee = (receipt, gateway) => {
29
+ if (gateway === 'shopify_payments') {
30
+ const { metadata, purchase_units } = Object.assign({}, receipt);
31
+ const fromPU = _fromPurchaseUnits(receipt);
32
+ if (fromPU !== null)
33
+ return fromPU;
34
+ const { transaction_fee_total_amount } = Object.assign({}, metadata);
35
+ if (!transaction_fee_total_amount)
36
+ return null;
37
+ const n = parseFloat(transaction_fee_total_amount);
38
+ if (isNaN(n))
39
+ return null;
40
+ return n / 100;
41
+ }
42
+ const { fee_amount } = Object.assign({}, receipt);
43
+ if (fee_amount) {
44
+ const n = parseFloat(fee_amount);
45
+ if (!isNaN(n))
46
+ return n;
47
+ }
48
+ return null;
49
+ };
50
+ exports._parseFee = _parseFee;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pintahub/shopify-api",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",