New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@swp/pay-sdk

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swp/pay-sdk - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

46

__tests__/__stubs.js

@@ -19,27 +19,49 @@ const swp = require("../lib/js/src/SwpPaySdk");

initial: {
payment: {
current_payments: [{
status: swp.paymentStatus.WaitingPayment,
is_expired: false
},
is_expired: false,
deposits: [],
}],
is_expired: false
},
underpaiment: {
payment: {
current_payments: [{
status: swp.paymentStatus.Underpayment,
is_expired: false
},
is_expired: false,
deposits: [],
}],
is_expired: false
},
newDeposit: {
current_payments: [{
is_expired: false,
deposits: [{
confirmations: 1,
}]
}],
is_expired: false
},
newDepositConfirmation: {
current_payments: [{
is_expired: false,
deposits: [{
confirmations: 2,
}]
}],
is_expired: false
},
expiredPayment: {
payment: {
current_payments: [{
status: swp.paymentStatus.Underpayment,
is_expired: true
},
is_expired: true,
deposits: [],
}],
is_expired: false
},
expired: {
payment: {
current_payments: [{
status: swp.paymentStatus.Underpayment,
is_expired: true
},
is_expired: true,
deposits: [],
}],
is_expired: true

@@ -46,0 +68,0 @@ }

@@ -15,2 +15,3 @@ const stubs = require("./__stubs")

getCheckout6: `${baseUrl}/checkouts/checkout-id-6`,
getCheckout7: `${baseUrl}/checkouts/checkout-id-7`,
}

@@ -26,2 +27,3 @@

[endpoints.getCheckout6]: jest.fn(),
[endpoints.getCheckout7]: jest.fn(),
}

@@ -49,3 +51,4 @@ }

paymentService.getCheckoutUpdates("checkout-id-1")
const checkoutUpdates = paymentService.getCheckoutUpdates("checkout-id-1")
checkoutUpdates.unsubscribe()

@@ -112,2 +115,3 @@ expect(mock.GET[endpoints.getCheckout1]).toBeCalled()

checkoutUpdates.events.on(swp.checkoutEvents.PaymentExpired, res => {
checkoutUpdates.unsubscribe()
expect(res).toEqual(stubs.checkoutResponses.expiredPayment)

@@ -142,2 +146,3 @@ expect(mock.GET[endpoints.getCheckout3]).toHaveBeenCalledTimes(2)

checkoutUpdates.events.on(swp.checkoutEvents.Expired, res => {
checkoutUpdates.unsubscribe()
expect(res).toEqual(stubs.checkoutResponses.expired)

@@ -197,2 +202,3 @@ expect(mock.GET[endpoints.getCheckout4]).toHaveBeenCalledTimes(2)

setTimeout(() => {
checkoutUpdates.unsubscribe()
expect(mock.GET[endpoints.getCheckout6]).toHaveBeenCalledTimes(1)

@@ -204,2 +210,40 @@

})
it("should listen to checkout NewDeposit and NewDepositConfirmation events", () => {
mock.GET[endpoints.getCheckout7]
.mockReturnValueOnce(
Promise.resolve({ json: () => Promise.resolve({ data: stubs.checkoutResponses.initial }) })
)
.mockReturnValueOnce(
Promise.resolve({ json: () => Promise.resolve({ data: stubs.checkoutResponses.newDeposit }) })
)
.mockReturnValueOnce(
Promise.resolve({ json: () => Promise.resolve({ data: stubs.checkoutResponses.newDepositConfirmation }) })
)
const paymentService = swp.init({
apiKey: stubs.apiKey,
secret: stubs.secret,
})
const checkoutUpdates = paymentService.getCheckoutUpdates(
"checkout-id-7",
50
)
const newDepositCallback = jest.fn()
const newDepositConfirmationCallback = jest.fn()
checkoutUpdates.events.on(swp.checkoutEvents.NewDeposit, newDepositCallback)
checkoutUpdates.events.on(swp.checkoutEvents.NewDepositConfirmation, newDepositConfirmationCallback)
return new Promise((resolve, _) => {
setTimeout(() => {
checkoutUpdates.unsubscribe()
expect(newDepositCallback).toHaveBeenCalledTimes(1)
expect(newDepositConfirmationCallback).toHaveBeenCalledTimes(1)
resolve()
}, 150)
})
})
})

@@ -115,10 +115,2 @@ 'use strict';

}
function caml_make_vect(len, init) {
var b = new Array(len);
for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){
b[i] = init;
}
return b;
}
/* No side effect */

@@ -319,15 +311,2 @@

function map(f, a) {
var l = a.length;
if (l === 0) {
return /* array */[];
} else {
var r = caml_make_vect(l, _1(f, a[0]));
for(var i = 1 ,i_finish = l - 1 | 0; i <= i_finish; ++i){
r[i] = _1(f, a[i]);
}
return r;
}
}
function iteri(f, a) {

@@ -677,2 +656,4 @@ for(var i = 0 ,i_finish = a.length - 1 | 0; i <= i_finish; ++i){

PaymentStatusChange: "payment-status-change",
NewDeposit: "new-deposit",
NewDepositConfirmation: "new-deposit-confirmation",
GetUpdatesError: "get-updates-error"

@@ -768,3 +749,3 @@ };

var lastCheckoutStatus = [/* Empty */0];
var lastPaymentStatus = [/* None */0];
var lastPayments = [/* None */0];
var ping$$1 = function () {

@@ -787,5 +768,5 @@ return _1(requestFn, /* () */0).then((function (prim) {

}
var match = lastPaymentStatus[0];
var match = lastPayments[0];
if (match) {
var lastStatus = match[0];
var lastPayments$1 = match[0];
iteri((function (i, p) {

@@ -795,10 +776,24 @@ if (p.is_expired) {

}
if (p.status !== caml_array_get(lastStatus, i)) {
if (p.status !== caml_array_get(lastPayments$1, i).status) {
emitter.emit("payment-status-change", checkout);
}
if (p.is_expired || toStatus(p.status) === /* Paid */3 || toStatus(p.status) === /* Overpayment */5) {
return clearIntervalRef(intervalRef[0]);
} else {
return 0;
var lastDeposits = caml_array_get(lastPayments$1, i).deposits;
var deposits = p.deposits;
if (deposits.length !== lastDeposits.length) {
emitter.emit("new-deposit", checkout);
}
return iteri((function (j, d) {
if (j < lastDeposits.length) {
var currentConfirmations = d.confirmations;
var lastConfirmations = caml_array_get(lastDeposits, j).confirmations;
if (currentConfirmations !== lastConfirmations) {
emitter.emit("new-deposit-confirmation", checkout);
return /* () */0;
} else {
return 0;
}
} else {
return 0;
}
}), deposits);
}), currentPayments);

@@ -808,5 +803,3 @@ } else {

}
return Promise.resolve((lastPaymentStatus[0] = /* Some */[map((function (p) {
return p.status;
}), currentPayments)], /* () */0));
return Promise.resolve((lastPayments[0] = /* Some */[currentPayments], /* () */0));
})).catch((function (err) {

@@ -813,0 +806,0 @@ return Promise.resolve((clearIntervalRef(intervalRef[0]), emitter.emit("get-updates-error", err), /* () */0));

@@ -126,2 +126,4 @@ declare module "swp-pay-sdk" {

PaymentStatusChange = "payment-status-change",
NewDeposit = "new-deposit",
NewDepositConfirmation = "new-deposit-confirmation",
GetUpdatesError = "get-updates-error"

@@ -128,0 +130,0 @@ }

{
"name": "@swp/pay-sdk",
"version": "0.1.3",
"version": "0.2.0",
"main": "dist/main",

@@ -5,0 +5,0 @@ "private": false,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc