@paystack/checkout-js 1.19.0-dev.9 → 1.19.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/es/checkout.js CHANGED
@@ -6403,16 +6403,14 @@ var devConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6403
6403
  paymentBaseUrl: 'https://legacy-staging.paystack.co/',
6404
6404
  paystackApiUrl: 'https://studio-api.paystack.co/',
6405
6405
  pusherKey: '1c7b262ee18455815893',
6406
- pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js',
6407
- savedCardsApiUrl: 'https://saved-cards-api.private.paystack.studio/'
6406
+ pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js'
6408
6407
  });
6409
6408
  var stagingConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6410
6409
  checkoutUrl: 'https://checkout-studio.paystack.com/',
6411
6410
  paymentBaseUrl: 'https://legacy-staging.paystack.co/',
6412
6411
  paystackApiUrl: 'https://studio-api.paystack.co/',
6413
6412
  pusherKey: '1c7b262ee18455815893',
6414
- pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js',
6415
- savedCardsApiUrl: 'https://saved-cards-api.private.paystack.studio/'
6413
+ pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js'
6416
6414
  });
6417
6415
  var productionConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6418
6416
  checkoutUrl: 'https://checkout.paystack.com/',
@@ -6430,37 +6428,6 @@ var configToEnvironmentMapping = {
6430
6428
  };
6431
6429
  var configToUse = configToEnvironmentMapping[env.paystackEnvironment] || productionConfig;
6432
6430
 
6433
- /* eslint-env browser */
6434
- // We use this function to load pusher.
6435
-
6436
- function loadPusher() {
6437
- if (!window) {
6438
- return Promise.reject(new Error('Window object not available'));
6439
- }
6440
-
6441
- return new Promise(function (resolve, reject) {
6442
- var xhr = new XMLHttpRequest();
6443
- xhr.open('GET', configToUse.pusherUrl);
6444
-
6445
- xhr.onload = function () {
6446
- if (xhr.status >= 200 && xhr.status < 300) {
6447
- var s = document.createElement('script');
6448
- s.appendChild(document.createTextNode(xhr.responseText));
6449
- document.head.appendChild(s);
6450
- resolve();
6451
- } else {
6452
- reject(xhr.statusText);
6453
- }
6454
- };
6455
-
6456
- xhr.onerror = function () {
6457
- return reject(xhr.statusText);
6458
- };
6459
-
6460
- xhr.send(null);
6461
- });
6462
- }
6463
-
6464
6431
  var noOp = function noOp() {
6465
6432
  return undefined;
6466
6433
  };
@@ -6634,6 +6601,82 @@ var ChargeResponses = {
6634
6601
  }
6635
6602
  };
6636
6603
 
6604
+ /* eslint-env browser */
6605
+
6606
+ var loadPusher = function loadPusher() {
6607
+ if (!window) {
6608
+ return Promise.reject(new Error('Window object not available'));
6609
+ }
6610
+
6611
+ return new Promise(function (resolve, reject) {
6612
+ var xhr = new XMLHttpRequest();
6613
+ xhr.open('GET', configToUse.pusherUrl);
6614
+
6615
+ xhr.onload = function () {
6616
+ if (xhr.status >= 200 && xhr.status < 300) {
6617
+ var s = document.createElement('script');
6618
+ s.appendChild(document.createTextNode(xhr.responseText));
6619
+ document.head.appendChild(s);
6620
+ resolve();
6621
+ } else {
6622
+ reject(xhr.statusText);
6623
+ }
6624
+ };
6625
+
6626
+ xhr.onerror = function () {
6627
+ return reject(xhr.statusText);
6628
+ };
6629
+
6630
+ xhr.send(null);
6631
+ });
6632
+ }; // `context` is passed through to set the class property of `isListening` to true/false
6633
+ // and provide the logAPIResponse analytics function
6634
+ // eslint-disable-next-line consistent-return
6635
+
6636
+ var subscribeToChargeEvents = function subscribeToChargeEvents(options, context, callback) {
6637
+ var channel = options.channel,
6638
+ paymentMethod = options.paymentMethod;
6639
+ var pusher;
6640
+
6641
+ if (window && window.Pusher) {
6642
+ pusher = new window.Pusher(configToUse.pusherKey, {
6643
+ cluster: 'eu',
6644
+ disableStats: true
6645
+ });
6646
+ }
6647
+
6648
+ var pusherUndefinedError = {
6649
+ status: 'error',
6650
+ message: 'We could not listen for charge response.'
6651
+ };
6652
+ var pusherSubscriptionError = {
6653
+ status: 'error',
6654
+ message: 'We could not listen for charge response. Use transaction.requery() to check the status.'
6655
+ };
6656
+
6657
+ var unsubscribeFromPusher = function unsubscribeFromPusher() {
6658
+ pusher.unsubscribe(channel);
6659
+ };
6660
+
6661
+ if (!pusher) {
6662
+ return callback(pusherUndefinedError, noOp);
6663
+ }
6664
+
6665
+ var pusherSubscription = pusher.subscribe(channel);
6666
+ pusherSubscription.bind('pusher:subscription_succeeded', function () {
6667
+ context.isListening = true;
6668
+ });
6669
+ pusherSubscription.bind('pusher:subscription_error', function () {
6670
+ context.isListening = false;
6671
+ callback(pusherSubscriptionError, noOp);
6672
+ });
6673
+ pusherSubscription.bind('response', function (response) {
6674
+ var formattedResponse = ChargeResponses.parse(response);
6675
+ context.logAPIResponse(formattedResponse, paymentMethod);
6676
+ callback(formattedResponse, unsubscribeFromPusher);
6677
+ });
6678
+ };
6679
+
6637
6680
  var uncurryThis$6 = functionUncurryThis;
6638
6681
  var PROPER_FUNCTION_NAME$1 = functionName.PROPER;
6639
6682
  var redefine$4 = redefine$a.exports;
@@ -18566,173 +18609,6 @@ var CardAPI = {
18566
18609
  }).then(function (response) {
18567
18610
  return ChargeResponses.parse(response.data);
18568
18611
  });
18569
- },
18570
- requestOtpForSavedCards: function requestOtpForSavedCards(phoneNumber) {
18571
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18572
- var url, language, headers, _yield$axiosInstance$, data;
18573
-
18574
- return regeneratorRuntime.wrap(function _callee$(_context) {
18575
- while (1) {
18576
- switch (_context.prev = _context.next) {
18577
- case 0:
18578
- url = new URL("/authorize/".concat(phoneNumber), configToUse.savedCardsApiUrl).toString();
18579
- language = getLanguage();
18580
- headers = _objectSpread2({}, language && {
18581
- 'Accept-Language': language
18582
- });
18583
- _context.next = 5;
18584
- return axiosInstance.post(url, {
18585
- headers: headers
18586
- });
18587
-
18588
- case 5:
18589
- _yield$axiosInstance$ = _context.sent;
18590
- data = _yield$axiosInstance$.data;
18591
- return _context.abrupt("return", data);
18592
-
18593
- case 8:
18594
- case "end":
18595
- return _context.stop();
18596
- }
18597
- }
18598
- }, _callee);
18599
- }))();
18600
- },
18601
- verifySavedCardsOtp: function verifySavedCardsOtp(_ref6) {
18602
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
18603
- var code, phone, transaction, url, language, headers, data, response;
18604
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
18605
- while (1) {
18606
- switch (_context2.prev = _context2.next) {
18607
- case 0:
18608
- code = _ref6.code, phone = _ref6.phone, transaction = _ref6.transaction;
18609
- url = new URL('/authorize/verify', configToUse.savedCardsApiUrl).toString();
18610
- language = getLanguage();
18611
- headers = _objectSpread2({}, language && {
18612
- 'Accept-Language': language
18613
- });
18614
- data = {
18615
- code: code,
18616
- phone: phone,
18617
- transaction: transaction
18618
- };
18619
- _context2.next = 7;
18620
- return axiosInstance.post(url, data, {
18621
- headers: headers
18622
- });
18623
-
18624
- case 7:
18625
- response = _context2.sent;
18626
- return _context2.abrupt("return", response.data);
18627
-
18628
- case 9:
18629
- case "end":
18630
- return _context2.stop();
18631
- }
18632
- }
18633
- }, _callee2);
18634
- }))();
18635
- },
18636
- getSavedCards: function getSavedCards(_ref7) {
18637
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
18638
- var token, url, language, headers, response;
18639
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
18640
- while (1) {
18641
- switch (_context3.prev = _context3.next) {
18642
- case 0:
18643
- token = _ref7.token;
18644
- url = new URL('/cards', configToUse.savedCardsApiUrl).toString();
18645
- language = getLanguage();
18646
- headers = _objectSpread2({
18647
- Authorization: "Bearer ".concat(token),
18648
- 'jwt-auth': true
18649
- }, language && {
18650
- 'Accept-Language': language
18651
- });
18652
- _context3.next = 6;
18653
- return axiosInstance.get(url, {
18654
- headers: headers
18655
- });
18656
-
18657
- case 6:
18658
- response = _context3.sent;
18659
- return _context3.abrupt("return", response.data);
18660
-
18661
- case 8:
18662
- case "end":
18663
- return _context3.stop();
18664
- }
18665
- }
18666
- }, _callee3);
18667
- }))();
18668
- },
18669
- deleteSavedCard: function deleteSavedCard(_ref8) {
18670
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
18671
- var cardCode, token, url, language, headers, response;
18672
- return regeneratorRuntime.wrap(function _callee4$(_context4) {
18673
- while (1) {
18674
- switch (_context4.prev = _context4.next) {
18675
- case 0:
18676
- cardCode = _ref8.cardCode, token = _ref8.token;
18677
- url = new URL("/cards/".concat(cardCode), configToUse.savedCardsApiUrl).toString();
18678
- language = getLanguage();
18679
- headers = _objectSpread2({
18680
- Authorization: "Bearer ".concat(token),
18681
- 'jwt-auth': true
18682
- }, language && {
18683
- 'Accept-Language': language
18684
- });
18685
- _context4.next = 6;
18686
- return axiosInstance.delete(url, {
18687
- headers: headers
18688
- });
18689
-
18690
- case 6:
18691
- response = _context4.sent;
18692
- return _context4.abrupt("return", response.data);
18693
-
18694
- case 8:
18695
- case "end":
18696
- return _context4.stop();
18697
- }
18698
- }
18699
- }, _callee4);
18700
- }))();
18701
- },
18702
- chargeSavedCard: function chargeSavedCard(_ref9) {
18703
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
18704
- var token, device, cardCode, transaction, selectedCurrency, url, language, headers, data;
18705
- return regeneratorRuntime.wrap(function _callee5$(_context5) {
18706
- while (1) {
18707
- switch (_context5.prev = _context5.next) {
18708
- case 0:
18709
- token = _ref9.token, device = _ref9.device, cardCode = _ref9.cardCode, transaction = _ref9.transaction, selectedCurrency = _ref9.selectedCurrency;
18710
- url = new URL("/cards/".concat(cardCode, "/charge"), configToUse.savedCardsApiUrl).toString();
18711
- language = getLanguage();
18712
- headers = _objectSpread2({
18713
- Authorization: "Bearer ".concat(token),
18714
- 'jwt-auth': true
18715
- }, language && {
18716
- 'Accept-Language': language
18717
- });
18718
- data = {
18719
- device: device,
18720
- transaction: transaction,
18721
- selectedCurrency: selectedCurrency
18722
- };
18723
- return _context5.abrupt("return", axiosInstance.post(url, data, {
18724
- headers: headers
18725
- }).then(function (response) {
18726
- return ChargeResponses.parse(response.data);
18727
- }));
18728
-
18729
- case 6:
18730
- case "end":
18731
- return _context5.stop();
18732
- }
18733
- }
18734
- }, _callee5);
18735
- }))();
18736
18612
  }
18737
18613
  };
18738
18614
 
@@ -18913,68 +18789,6 @@ var CardCharge = {
18913
18789
  paymentMethod: paymentMethod$3
18914
18790
  };
18915
18791
  return this.listenForCharge(listenerOptions, callback);
18916
- },
18917
- requestOtpForSavedCards: function requestOtpForSavedCards(phoneNumber) {
18918
- return CardAPI.requestOtpForSavedCards(phoneNumber);
18919
- },
18920
- verifySavedCardsOtp: function verifySavedCardsOtp(_ref4) {
18921
- var _this9 = this;
18922
-
18923
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18924
- var code, phone, payload, response;
18925
- return regeneratorRuntime.wrap(function _callee$(_context) {
18926
- while (1) {
18927
- switch (_context.prev = _context.next) {
18928
- case 0:
18929
- code = _ref4.code, phone = _ref4.phone;
18930
- payload = {
18931
- code: code,
18932
- phone: phone,
18933
- transaction: _this9.id
18934
- };
18935
- _context.prev = 2;
18936
- _context.next = 5;
18937
- return CardAPI.verifySavedCardsOtp(payload);
18938
-
18939
- case 5:
18940
- response = _context.sent;
18941
- _this9.savedCardsToken = response.data.token;
18942
- return _context.abrupt("return", response);
18943
-
18944
- case 10:
18945
- _context.prev = 10;
18946
- _context.t0 = _context["catch"](2);
18947
- _this9.savedCardsToken = null;
18948
- return _context.abrupt("return", new Error(_context.t0));
18949
-
18950
- case 14:
18951
- case "end":
18952
- return _context.stop();
18953
- }
18954
- }
18955
- }, _callee, null, [[2, 10]]);
18956
- }))();
18957
- },
18958
- getSavedCards: function getSavedCards() {
18959
- return CardAPI.getSavedCards({
18960
- token: this.savedCardsToken
18961
- });
18962
- },
18963
- deleteSavedCard: function deleteSavedCard(cardCode) {
18964
- return CardAPI.deleteSavedCard({
18965
- cardCode: cardCode,
18966
- token: this.savedCardsToken
18967
- });
18968
- },
18969
- chargeSavedCard: function chargeSavedCard(_ref5) {
18970
- var cardCode = _ref5.cardCode;
18971
- return CardAPI.chargeSavedCard({
18972
- cardCode: cardCode,
18973
- transaction: this.id,
18974
- token: this.savedCardsToken,
18975
- device: this.deviceFingerprint,
18976
- selectedCurrency: this.currency
18977
- });
18978
18792
  }
18979
18793
  };
18980
18794
 
@@ -20303,8 +20117,6 @@ var TransactionInstance = /*#__PURE__*/function () {
20303
20117
  this.subscription = data.subscription || null;
20304
20118
  this.planDetails = data.plan_details || null;
20305
20119
  this.exchangeRate = data.exchange_rate || null;
20306
- this.savedCardsToken = null;
20307
- this.isSavedCardsEnabled = data.saved_cards && data.saved_cards.enabled || null;
20308
20120
  /**
20309
20121
  * We initialize parameters we send to the API as empty strings
20310
20122
  * when we don't have them instead of null because the API expects
@@ -20347,51 +20159,7 @@ var TransactionInstance = /*#__PURE__*/function () {
20347
20159
  }, {
20348
20160
  key: "listenForCharge",
20349
20161
  value: function listenForCharge(options, callback) {
20350
- var _this2 = this;
20351
-
20352
- var channel = options.channel,
20353
- paymentMethod = options.paymentMethod;
20354
- var pusher;
20355
-
20356
- if (window && window.Pusher) {
20357
- pusher = new window.Pusher(configToUse.pusherKey, {
20358
- cluster: 'eu',
20359
- disableStats: true
20360
- });
20361
- }
20362
-
20363
- var pusherUndefinedError = {
20364
- status: 'error',
20365
- message: 'We could not listen for charge response.'
20366
- };
20367
- var pusherSubscriptionError = {
20368
- status: 'error',
20369
- message: 'We could not listen for charge response. Use transaction.requery() to check the status.'
20370
- };
20371
-
20372
- var unsubscribeFromPusher = function unsubscribeFromPusher() {
20373
- pusher.unsubscribe(channel);
20374
- };
20375
-
20376
- if (!pusher) {
20377
- return callback(pusherUndefinedError, noOp);
20378
- }
20379
-
20380
- var pusherSubscription = pusher.subscribe(channel);
20381
- pusherSubscription.bind('pusher:subscription_succeeded', function () {
20382
- _this2.isListening = true;
20383
- });
20384
- pusherSubscription.bind('pusher:subscription_error', function () {
20385
- _this2.isListening = false;
20386
- callback(pusherSubscriptionError, noOp);
20387
- });
20388
- pusherSubscription.bind('response', function (response) {
20389
- var formattedResponse = ChargeResponses.parse(response);
20390
-
20391
- _this2.logAPIResponse(formattedResponse, paymentMethod);
20392
-
20393
- callback(formattedResponse, unsubscribeFromPusher);
20394
- });
20162
+ return subscribeToChargeEvents(options, this, callback);
20395
20163
  }
20396
20164
  }, {
20397
20165
  key: "requery",
@@ -20689,4 +20457,105 @@ var Toolkit = /*#__PURE__*/function () {
20689
20457
  return Toolkit;
20690
20458
  }();
20691
20459
 
20692
- export { BankAccount, Card, Toolkit, Transaction };
20460
+ var PreauthorizationInstance = /*#__PURE__*/function () {
20461
+ function PreauthorizationInstance(data) {
20462
+ _classCallCheck(this, PreauthorizationInstance);
20463
+
20464
+ this.email = data.email;
20465
+ this.status = data.status;
20466
+ this.reference = data.reference;
20467
+ this.amount = data.amount;
20468
+ this.currency = data.currency;
20469
+ this.metadata = data.metadata || {};
20470
+ this.customer = data.customer;
20471
+ this.channels = data.channels || ['card'];
20472
+ this.isListening = false;
20473
+ this.merchant = {
20474
+ id: data.merchant_id,
20475
+ logo: data.merchant_logo,
20476
+ name: data.merchant_name,
20477
+ key: data.merchant_key
20478
+ };
20479
+ loadPusher(); // TODO: Bind charge function to card channel
20480
+ // https://paystack.atlassian.net/browse/RAILS-2887
20481
+ }
20482
+
20483
+ _createClass(PreauthorizationInstance, [{
20484
+ key: "setMetadata",
20485
+ value: function setMetadata(key, value) {
20486
+ this.metadata[key] = value;
20487
+ }
20488
+ }, {
20489
+ key: "listenForCharge",
20490
+ value: function listenForCharge(options, callback) {
20491
+ return subscribeToChargeEvents(options, this, callback);
20492
+ }
20493
+ }]);
20494
+
20495
+ return PreauthorizationInstance;
20496
+ }();
20497
+
20498
+ var PreauthorisationAPI = {
20499
+ getByAccessCode: function getByAccessCode(accessCode) {
20500
+ var language = getLanguage();
20501
+
20502
+ var headers = _objectSpread2({}, language && {
20503
+ 'Accept-Language': language
20504
+ });
20505
+
20506
+ var url = "".concat(configToUse.paystackApiUrl, "preauthorization/verify_access_code/").concat(accessCode);
20507
+ return axiosInstance.get(url, {
20508
+ headers: headers
20509
+ }).then(function (response) {
20510
+ return response.data;
20511
+ });
20512
+ },
20513
+ requery: function requery() {// TODO: https://paystack.atlassian.net/browse/RAILS-2890
20514
+ },
20515
+ reserveFunds: function reserveFunds() {// TODO: https://paystack.atlassian.net/browse/RAILS-2887
20516
+ }
20517
+ };
20518
+
20519
+ var Preauthorization = {
20520
+ initialize: function initialize(data) {
20521
+ return Object.seal(new PreauthorizationInstance(data));
20522
+ },
20523
+ getByAccessCode: function getByAccessCode(accessCode) {
20524
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
20525
+ var response;
20526
+ return regeneratorRuntime.wrap(function _callee$(_context) {
20527
+ while (1) {
20528
+ switch (_context.prev = _context.next) {
20529
+ case 0:
20530
+ _context.next = 2;
20531
+ return PreauthorisationAPI.getByAccessCode(accessCode);
20532
+
20533
+ case 2:
20534
+ response = _context.sent;
20535
+ return _context.abrupt("return", response && Object.seal(new PreauthorizationInstance(_objectSpread2({}, response.data))));
20536
+
20537
+ case 4:
20538
+ case "end":
20539
+ return _context.stop();
20540
+ }
20541
+ }
20542
+ }, _callee);
20543
+ }))();
20544
+ },
20545
+ verify: function verify() {// TODO: https://paystack.atlassian.net/browse/RAILS-2890
20546
+
20547
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
20548
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
20549
+ while (1) {
20550
+ switch (_context2.prev = _context2.next) {
20551
+ case 0:
20552
+ case "end":
20553
+ return _context2.stop();
20554
+ }
20555
+ }
20556
+ }, _callee2);
20557
+ }))();
20558
+ }
20559
+ };
20560
+
20561
+ export { BankAccount, Card, Preauthorization, Toolkit, Transaction };