@paystack/checkout-js 1.57.0-beta.10 → 1.57.0-beta.11

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/checkout.js CHANGED
@@ -6532,8 +6532,6 @@ var Paystack = (function (exports) {
6532
6532
  if (response.auth && response.auth !== 'none') {
6533
6533
  return this.auth(response);
6534
6534
  }
6535
- // Below the auth check and gated on `url`: an open_url hand-off is only actionable with an
6536
- // address, and anything still carrying `auth` is an authentication response first.
6537
6535
  if (response.status === 'open_url' && response.url) {
6538
6536
  return this.getCleanResponse(response, 'Continue at the payment provider');
6539
6537
  }
@@ -21348,9 +21346,6 @@ var Paystack = (function (exports) {
21348
21346
  });
21349
21347
  }
21350
21348
 
21351
- // A 4xx is the server refusing the charge, and its body carries the merchant-safe reason, so parse
21352
- // it rather than let axios discard it. A 5xx is not a refusal — it answers "try again later" and
21353
- // may even land after the order was created — so it rethrows, same as the status poll below.
21354
21349
  var parseChargeRefusal = function parseChargeRefusal(error) {
21355
21350
  if (!error.response || error.response.status >= 500) throw error;
21356
21351
  return ChargeResponses.parse(error.response.data);
@@ -21392,9 +21387,6 @@ var Paystack = (function (exports) {
21392
21387
  return ChargeResponses.parse(response.data);
21393
21388
  }).catch(parseChargeRefusal);
21394
21389
  },
21395
- // Deliberately has no error branch. Only a 2xx body is an answer about the payment; a 404, a
21396
- // proxy 5xx or an expired key is the poll failing to reach a verdict, and resolving those to
21397
- // `failed` would have checkout conclude an outcome the server never gave it.
21398
21390
  requery: function requery(_ref2) {
21399
21391
  var transactionReference = _ref2.transactionReference,
21400
21392
  publicKey = _ref2.publicKey;
@@ -21413,24 +21405,36 @@ var Paystack = (function (exports) {
21413
21405
  }
21414
21406
  };
21415
21407
 
21416
- // eslint-disable-next-line import/prefer-default-export
21417
21408
  var PAYFLEX_CHANNEL = 'payflex';
21418
21409
 
21419
- // Checkout may never conclude failure on a timer, so the poll runs long and overlaps: a timer, a
21420
- // window-focus re-check and a Pusher event can all be in flight together. saveLog() re-POSTs the
21421
- // whole history per entry, so a run gets one pending entry. A hand-off starts a run; success or
21422
- // failure ends it; a straggler resolving after either is dropped. The hand-off has to reset on its
21423
- // own because a Pusher outcome concludes without passing through requeryPayflex.
21424
21410
  var pollRuns = new WeakMap();
21425
21411
  var runFor = function runFor(transaction) {
21426
21412
  if (!pollRuns.has(transaction)) {
21427
21413
  pollRuns.set(transaction, {
21428
21414
  pendingLogged: false,
21429
- concluded: false
21415
+ concluded: false,
21416
+ lastOutcome: null
21430
21417
  });
21431
21418
  }
21432
21419
  return pollRuns.get(transaction);
21433
21420
  };
21421
+ var isTerminal = function isTerminal(status) {
21422
+ return status === 'success' || status === 'failed';
21423
+ };
21424
+ var recordOutcome = function recordOutcome(transaction, response) {
21425
+ var run = runFor(transaction);
21426
+ if (isTerminal(response.status)) {
21427
+ if (run.lastOutcome === response.status) return false;
21428
+ run.concluded = true;
21429
+ run.pendingLogged = false;
21430
+ run.lastOutcome = response.status;
21431
+ return true;
21432
+ }
21433
+ if (response.status !== 'pending') return true;
21434
+ if (run.pendingLogged || run.concluded) return false;
21435
+ run.pendingLogged = true;
21436
+ return true;
21437
+ };
21434
21438
  var PayflexCharge = {
21435
21439
  chargePayflex: function chargePayflex() {
21436
21440
  var _this = this;
@@ -21470,26 +21474,22 @@ var Paystack = (function (exports) {
21470
21474
  transactionReference: this.reference,
21471
21475
  publicKey: this.merchant.key
21472
21476
  }).then(function (response) {
21473
- var run = runFor(_this2);
21474
- if (response.status === 'success' || response.status === 'failed') {
21475
- run.concluded = true;
21476
- run.pendingLogged = false;
21477
- _this2.logAPIResponse(response, PAYFLEX_CHANNEL);
21478
- } else if (response.status !== 'pending') {
21479
- _this2.logAPIResponse(response, PAYFLEX_CHANNEL);
21480
- } else if (!run.pendingLogged && !run.concluded) {
21481
- run.pendingLogged = true;
21477
+ if (recordOutcome(_this2, response)) {
21482
21478
  _this2.logAPIResponse(response, PAYFLEX_CHANNEL);
21483
21479
  }
21484
21480
  return response;
21485
21481
  });
21486
21482
  },
21487
21483
  listenForPayflexCharge: function listenForPayflexCharge(callback) {
21484
+ var _this3 = this;
21488
21485
  var listenerOptions = {
21489
21486
  paymentMethod: PAYFLEX_CHANNEL,
21490
21487
  channel: "PAYFLEX_".concat(this.id)
21491
21488
  };
21492
- return this.listenForCharge(listenerOptions, callback);
21489
+ return this.listenForCharge(listenerOptions, function (response, unsubscribe) {
21490
+ recordOutcome(_this3, response);
21491
+ callback(response, unsubscribe);
21492
+ });
21493
21493
  }
21494
21494
  };
21495
21495
 
package/es/checkout.js CHANGED
@@ -6529,8 +6529,6 @@ var ChargeResponses = {
6529
6529
  if (response.auth && response.auth !== 'none') {
6530
6530
  return this.auth(response);
6531
6531
  }
6532
- // Below the auth check and gated on `url`: an open_url hand-off is only actionable with an
6533
- // address, and anything still carrying `auth` is an authentication response first.
6534
6532
  if (response.status === 'open_url' && response.url) {
6535
6533
  return this.getCleanResponse(response, 'Continue at the payment provider');
6536
6534
  }
@@ -21345,9 +21343,6 @@ if (NATIVE_WEAK_MAP && IS_IE11) {
21345
21343
  });
21346
21344
  }
21347
21345
 
21348
- // A 4xx is the server refusing the charge, and its body carries the merchant-safe reason, so parse
21349
- // it rather than let axios discard it. A 5xx is not a refusal — it answers "try again later" and
21350
- // may even land after the order was created — so it rethrows, same as the status poll below.
21351
21346
  var parseChargeRefusal = function parseChargeRefusal(error) {
21352
21347
  if (!error.response || error.response.status >= 500) throw error;
21353
21348
  return ChargeResponses.parse(error.response.data);
@@ -21389,9 +21384,6 @@ var PayflexAPI = {
21389
21384
  return ChargeResponses.parse(response.data);
21390
21385
  }).catch(parseChargeRefusal);
21391
21386
  },
21392
- // Deliberately has no error branch. Only a 2xx body is an answer about the payment; a 404, a
21393
- // proxy 5xx or an expired key is the poll failing to reach a verdict, and resolving those to
21394
- // `failed` would have checkout conclude an outcome the server never gave it.
21395
21387
  requery: function requery(_ref2) {
21396
21388
  var transactionReference = _ref2.transactionReference,
21397
21389
  publicKey = _ref2.publicKey;
@@ -21410,24 +21402,36 @@ var PayflexAPI = {
21410
21402
  }
21411
21403
  };
21412
21404
 
21413
- // eslint-disable-next-line import/prefer-default-export
21414
21405
  var PAYFLEX_CHANNEL = 'payflex';
21415
21406
 
21416
- // Checkout may never conclude failure on a timer, so the poll runs long and overlaps: a timer, a
21417
- // window-focus re-check and a Pusher event can all be in flight together. saveLog() re-POSTs the
21418
- // whole history per entry, so a run gets one pending entry. A hand-off starts a run; success or
21419
- // failure ends it; a straggler resolving after either is dropped. The hand-off has to reset on its
21420
- // own because a Pusher outcome concludes without passing through requeryPayflex.
21421
21407
  var pollRuns = new WeakMap();
21422
21408
  var runFor = function runFor(transaction) {
21423
21409
  if (!pollRuns.has(transaction)) {
21424
21410
  pollRuns.set(transaction, {
21425
21411
  pendingLogged: false,
21426
- concluded: false
21412
+ concluded: false,
21413
+ lastOutcome: null
21427
21414
  });
21428
21415
  }
21429
21416
  return pollRuns.get(transaction);
21430
21417
  };
21418
+ var isTerminal = function isTerminal(status) {
21419
+ return status === 'success' || status === 'failed';
21420
+ };
21421
+ var recordOutcome = function recordOutcome(transaction, response) {
21422
+ var run = runFor(transaction);
21423
+ if (isTerminal(response.status)) {
21424
+ if (run.lastOutcome === response.status) return false;
21425
+ run.concluded = true;
21426
+ run.pendingLogged = false;
21427
+ run.lastOutcome = response.status;
21428
+ return true;
21429
+ }
21430
+ if (response.status !== 'pending') return true;
21431
+ if (run.pendingLogged || run.concluded) return false;
21432
+ run.pendingLogged = true;
21433
+ return true;
21434
+ };
21431
21435
  var PayflexCharge = {
21432
21436
  chargePayflex: function chargePayflex() {
21433
21437
  var _this = this;
@@ -21467,26 +21471,22 @@ var PayflexCharge = {
21467
21471
  transactionReference: this.reference,
21468
21472
  publicKey: this.merchant.key
21469
21473
  }).then(function (response) {
21470
- var run = runFor(_this2);
21471
- if (response.status === 'success' || response.status === 'failed') {
21472
- run.concluded = true;
21473
- run.pendingLogged = false;
21474
- _this2.logAPIResponse(response, PAYFLEX_CHANNEL);
21475
- } else if (response.status !== 'pending') {
21476
- _this2.logAPIResponse(response, PAYFLEX_CHANNEL);
21477
- } else if (!run.pendingLogged && !run.concluded) {
21478
- run.pendingLogged = true;
21474
+ if (recordOutcome(_this2, response)) {
21479
21475
  _this2.logAPIResponse(response, PAYFLEX_CHANNEL);
21480
21476
  }
21481
21477
  return response;
21482
21478
  });
21483
21479
  },
21484
21480
  listenForPayflexCharge: function listenForPayflexCharge(callback) {
21481
+ var _this3 = this;
21485
21482
  var listenerOptions = {
21486
21483
  paymentMethod: PAYFLEX_CHANNEL,
21487
21484
  channel: "PAYFLEX_".concat(this.id)
21488
21485
  };
21489
- return this.listenForCharge(listenerOptions, callback);
21486
+ return this.listenForCharge(listenerOptions, function (response, unsubscribe) {
21487
+ recordOutcome(_this3, response);
21488
+ callback(response, unsubscribe);
21489
+ });
21490
21490
  }
21491
21491
  };
21492
21492
 
package/lib/checkout.js CHANGED
@@ -6533,8 +6533,6 @@ var ChargeResponses = {
6533
6533
  if (response.auth && response.auth !== 'none') {
6534
6534
  return this.auth(response);
6535
6535
  }
6536
- // Below the auth check and gated on `url`: an open_url hand-off is only actionable with an
6537
- // address, and anything still carrying `auth` is an authentication response first.
6538
6536
  if (response.status === 'open_url' && response.url) {
6539
6537
  return this.getCleanResponse(response, 'Continue at the payment provider');
6540
6538
  }
@@ -21349,9 +21347,6 @@ if (NATIVE_WEAK_MAP && IS_IE11) {
21349
21347
  });
21350
21348
  }
21351
21349
 
21352
- // A 4xx is the server refusing the charge, and its body carries the merchant-safe reason, so parse
21353
- // it rather than let axios discard it. A 5xx is not a refusal — it answers "try again later" and
21354
- // may even land after the order was created — so it rethrows, same as the status poll below.
21355
21350
  var parseChargeRefusal = function parseChargeRefusal(error) {
21356
21351
  if (!error.response || error.response.status >= 500) throw error;
21357
21352
  return ChargeResponses.parse(error.response.data);
@@ -21393,9 +21388,6 @@ var PayflexAPI = {
21393
21388
  return ChargeResponses.parse(response.data);
21394
21389
  }).catch(parseChargeRefusal);
21395
21390
  },
21396
- // Deliberately has no error branch. Only a 2xx body is an answer about the payment; a 404, a
21397
- // proxy 5xx or an expired key is the poll failing to reach a verdict, and resolving those to
21398
- // `failed` would have checkout conclude an outcome the server never gave it.
21399
21391
  requery: function requery(_ref2) {
21400
21392
  var transactionReference = _ref2.transactionReference,
21401
21393
  publicKey = _ref2.publicKey;
@@ -21414,24 +21406,36 @@ var PayflexAPI = {
21414
21406
  }
21415
21407
  };
21416
21408
 
21417
- // eslint-disable-next-line import/prefer-default-export
21418
21409
  var PAYFLEX_CHANNEL = 'payflex';
21419
21410
 
21420
- // Checkout may never conclude failure on a timer, so the poll runs long and overlaps: a timer, a
21421
- // window-focus re-check and a Pusher event can all be in flight together. saveLog() re-POSTs the
21422
- // whole history per entry, so a run gets one pending entry. A hand-off starts a run; success or
21423
- // failure ends it; a straggler resolving after either is dropped. The hand-off has to reset on its
21424
- // own because a Pusher outcome concludes without passing through requeryPayflex.
21425
21411
  var pollRuns = new WeakMap();
21426
21412
  var runFor = function runFor(transaction) {
21427
21413
  if (!pollRuns.has(transaction)) {
21428
21414
  pollRuns.set(transaction, {
21429
21415
  pendingLogged: false,
21430
- concluded: false
21416
+ concluded: false,
21417
+ lastOutcome: null
21431
21418
  });
21432
21419
  }
21433
21420
  return pollRuns.get(transaction);
21434
21421
  };
21422
+ var isTerminal = function isTerminal(status) {
21423
+ return status === 'success' || status === 'failed';
21424
+ };
21425
+ var recordOutcome = function recordOutcome(transaction, response) {
21426
+ var run = runFor(transaction);
21427
+ if (isTerminal(response.status)) {
21428
+ if (run.lastOutcome === response.status) return false;
21429
+ run.concluded = true;
21430
+ run.pendingLogged = false;
21431
+ run.lastOutcome = response.status;
21432
+ return true;
21433
+ }
21434
+ if (response.status !== 'pending') return true;
21435
+ if (run.pendingLogged || run.concluded) return false;
21436
+ run.pendingLogged = true;
21437
+ return true;
21438
+ };
21435
21439
  var PayflexCharge = {
21436
21440
  chargePayflex: function chargePayflex() {
21437
21441
  var _this = this;
@@ -21471,26 +21475,22 @@ var PayflexCharge = {
21471
21475
  transactionReference: this.reference,
21472
21476
  publicKey: this.merchant.key
21473
21477
  }).then(function (response) {
21474
- var run = runFor(_this2);
21475
- if (response.status === 'success' || response.status === 'failed') {
21476
- run.concluded = true;
21477
- run.pendingLogged = false;
21478
- _this2.logAPIResponse(response, PAYFLEX_CHANNEL);
21479
- } else if (response.status !== 'pending') {
21480
- _this2.logAPIResponse(response, PAYFLEX_CHANNEL);
21481
- } else if (!run.pendingLogged && !run.concluded) {
21482
- run.pendingLogged = true;
21478
+ if (recordOutcome(_this2, response)) {
21483
21479
  _this2.logAPIResponse(response, PAYFLEX_CHANNEL);
21484
21480
  }
21485
21481
  return response;
21486
21482
  });
21487
21483
  },
21488
21484
  listenForPayflexCharge: function listenForPayflexCharge(callback) {
21485
+ var _this3 = this;
21489
21486
  var listenerOptions = {
21490
21487
  paymentMethod: PAYFLEX_CHANNEL,
21491
21488
  channel: "PAYFLEX_".concat(this.id)
21492
21489
  };
21493
- return this.listenForCharge(listenerOptions, callback);
21490
+ return this.listenForCharge(listenerOptions, function (response, unsubscribe) {
21491
+ recordOutcome(_this3, response);
21492
+ callback(response, unsubscribe);
21493
+ });
21494
21494
  }
21495
21495
  };
21496
21496
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paystack/checkout-js",
3
- "version": "1.57.0-beta.10",
3
+ "version": "1.57.0-beta.11",
4
4
  "description": "Client-side JS library for billing on Paystack",
5
5
  "main": "lib/checkout.js",
6
6
  "module": "es/checkout.js",