Comparing version 1.3.0 to 1.3.1
@@ -14,2 +14,16 @@ import PinAPI from "../lib"; | ||
let newSubscription = null; | ||
const cancelStructure = { | ||
plan_token: expect.any(String), | ||
token: expect.any(String), | ||
customer_token: expect.any(String), | ||
card_token: null, | ||
state: expect.any(String), | ||
current_period_started_at: expect.any(String), | ||
current_period_ends_at: expect.any(String), | ||
active_interval_started_at: expect.any(String), | ||
active_interval_finishes_at: expect.any(String), | ||
cancelled_at: null, | ||
next_billing_date: null, | ||
created_at: expect.any(String) | ||
}; | ||
@@ -60,2 +74,12 @@ describe("Subscription Enpoints", () => { | ||
}); | ||
describe("cancelSubscription", () => { | ||
it("returns expected subscription", () => { | ||
return api | ||
.cancelSubscription({ token: newSubscription.token }) | ||
.then(response => { | ||
expect(response).toEqual(cancelStructure); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -1,1 +0,1 @@ | ||
"use strict";var _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a},_request=require("request"),_request2=_interopRequireDefault(_request),_undefsafe=require("undefsafe"),_undefsafe2=_interopRequireDefault(_undefsafe);Object.defineProperty(exports,"__esModule",{value:!0});function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _objectWithoutProperties(a,b){var c={};for(var d in a)0<=b.indexOf(d)||Object.prototype.hasOwnProperty.call(a,d)&&(c[d]=a[d]);return c}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var apiVersion="1",liveUrl="https://api.pin.net.au",testUrl="https://test-api.pin.net.au",MODE={POST:"post",GET:"get",PUT:"put",DELETE:"delete"},ENDPOINT={CUSTOMER:"customers",CHARGES:"charges",CARDS:"cards",SUBSCRIPTIONS:"subscriptions",PLANS:"plans"},DELETE=204,PinAPI=function a(b){var c=this;_classCallCheck(this,a),this.setApiUrl=function(a){c.apiUrl=a?liveUrl:testUrl},this.formatResponse=function(){},this.handleAuthentication=function(a){a.auth(c.key,"")},this.handleErrorResponse=function(a,b){console.log(a),b(a)},this.handleSuccessResponse=function(a,b,c){var d=b;(0,_undefsafe2.default)(b,"response")&&(0,_undefsafe2.default)(b,"pagination")===void 0&&(d=b.response),a.statusCode===DELETE&&(d={success:!0}),c(d)},this.makeRequest=function(a){var b=a.token,d=a.body,e=a.endpoint,f=a.mode,g=a.debug,h=c.apiUrl+"/"+apiVersion+"/"+e.primary;return(0,_undefsafe2.default)(b,"primary")&&(h+="/"+b.primary),(0,_undefsafe2.default)(e,"secondary")&&(h+="/"+e.secondary),(0,_undefsafe2.default)(b,"secondary")&&(h+="/"+b.secondary),new Promise(function(a,b){var e=_request2.default[f]({url:h,json:!0,body:d},function(d,e,f){d?c.handleErrorResponse(d,b):g?a({url:h,body:f}):c.handleSuccessResponse(e,f,a)});c.handleAuthentication(e)})},this.createCustomer=function(a){return c.makeRequest({body:a,endpoint:{primary:ENDPOINT.CUSTOMER},mode:MODE.POST})},this.fetchAllCustomers=function(a){return c.makeRequest({body:a,endpoint:{primary:ENDPOINT.CUSTOMER},mode:MODE.GET})},this.fetchCustomer=function(a){return c.makeRequest({token:{primary:a},endpoint:{primary:ENDPOINT.CUSTOMER},mode:MODE.GET})},this.updateCustomer=function(a,b){return c.makeRequest({token:{primary:a},body:b,endpoint:{primary:ENDPOINT.CUSTOMER},mode:MODE.PUT})},this.deleteCustomer=function(a){return c.makeRequest({token:{primary:a},endpoint:{primary:ENDPOINT.CUSTOMER},mode:MODE.DELETE})},this.customerCharges=function(a){return c.makeRequest({token:{primary:a},endpoint:{primary:ENDPOINT.CUSTOMER,secondary:ENDPOINT.CHARGES},mode:MODE.GET})},this.customerCards=function(a){return c.makeRequest({token:{primary:a},endpoint:{primary:ENDPOINT.CUSTOMER,secondary:ENDPOINT.CARDS},mode:MODE.GET})},this.createCustomerCard=function(a,b){return c.makeRequest({body:a,token:{primary:b},endpoint:{primary:ENDPOINT.CUSTOMER,secondary:ENDPOINT.CARDS},mode:MODE.POST})},this.deleteCustomerCard=function(a,b){return c.makeRequest({token:{primary:a,secondary:b},endpoint:{primary:ENDPOINT.CUSTOMER,secondary:ENDPOINT.CARDS},mode:MODE.DELETE})},this.createCharge=function(a){return c.makeRequest({body:a,endpoint:{primary:ENDPOINT.CHARGES},mode:MODE.POST})},this.createCard=function(a){return c.makeRequest({body:a,endpoint:{primary:ENDPOINT.CARDS},mode:MODE.POST})},this.fetchAllPlans=function(a){return c.makeRequest({body:a,endpoint:{primary:ENDPOINT.PLANS},mode:MODE.GET})},this.fetchPlan=function(a){var b=a.token;return c.makeRequest({token:{primary:b},endpoint:{primary:ENDPOINT.PLANS},mode:MODE.GET})},this.createSubscription=function(a){var b=a.customerToken,d=a.planToken,e=_objectWithoutProperties(a,["customerToken","planToken"]);return c.makeRequest({body:_extends({customer_token:b,plan_token:d},e),endpoint:{primary:ENDPOINT.SUBSCRIPTIONS},mode:MODE.POST})},this.fetchSubscription=function(a){var b=a.token;return c.makeRequest({token:{primary:b},endpoint:{primary:ENDPOINT.SUBSCRIPTIONS},mode:MODE.GET})},this.key=b.key,this.live=b.live,this.setApiUrl()};exports.default=PinAPI; | ||
"use strict";var _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a},_request=require("request"),_request2=_interopRequireDefault(_request),_undefsafe=require("undefsafe"),_undefsafe2=_interopRequireDefault(_undefsafe);Object.defineProperty(exports,"__esModule",{value:!0});function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _objectWithoutProperties(a,b){var c={};for(var d in a)0<=b.indexOf(d)||Object.prototype.hasOwnProperty.call(a,d)&&(c[d]=a[d]);return c}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var apiVersion="1",liveUrl="https://api.pin.net.au",testUrl="https://test-api.pin.net.au",MODE={POST:"post",GET:"get",PUT:"put",DELETE:"delete"},ENDPOINT={CUSTOMER:"customers",CHARGES:"charges",CARDS:"cards",SUBSCRIPTIONS:"subscriptions",PLANS:"plans"},DELETE=204,PinAPI=function a(b){var c=this;_classCallCheck(this,a),this.setApiUrl=function(a){c.apiUrl=a?liveUrl:testUrl},this.formatResponse=function(){},this.handleAuthentication=function(a){a.auth(c.key,"")},this.handleErrorResponse=function(a,b){console.log(a),b(a)},this.handleSuccessResponse=function(a,b,c){var d=b;(0,_undefsafe2.default)(b,"response")&&(0,_undefsafe2.default)(b,"pagination")===void 0&&(d=b.response),a.statusCode===DELETE&&(d={success:!0}),c(d)},this.makeRequest=function(a){var b=a.token,d=a.body,e=a.endpoint,f=a.mode,g=a.debug,h=c.apiUrl+"/"+apiVersion+"/"+e.primary;return(0,_undefsafe2.default)(b,"primary")&&(h+="/"+b.primary),(0,_undefsafe2.default)(e,"secondary")&&(h+="/"+e.secondary),(0,_undefsafe2.default)(b,"secondary")&&(h+="/"+b.secondary),new Promise(function(a,b){var e=_request2.default[f]({url:h,json:!0,body:d},function(d,e,f){d?c.handleErrorResponse(d,b):g?a({url:h,body:f}):c.handleSuccessResponse(e,f,a)});c.handleAuthentication(e)})},this.createCustomer=function(a){return c.makeRequest({body:a,endpoint:{primary:ENDPOINT.CUSTOMER},mode:MODE.POST})},this.fetchAllCustomers=function(a){return c.makeRequest({body:a,endpoint:{primary:ENDPOINT.CUSTOMER},mode:MODE.GET})},this.fetchCustomer=function(a){return c.makeRequest({token:{primary:a},endpoint:{primary:ENDPOINT.CUSTOMER},mode:MODE.GET})},this.updateCustomer=function(a,b){return c.makeRequest({token:{primary:a},body:b,endpoint:{primary:ENDPOINT.CUSTOMER},mode:MODE.PUT})},this.deleteCustomer=function(a){return c.makeRequest({token:{primary:a},endpoint:{primary:ENDPOINT.CUSTOMER},mode:MODE.DELETE})},this.customerCharges=function(a){return c.makeRequest({token:{primary:a},endpoint:{primary:ENDPOINT.CUSTOMER,secondary:ENDPOINT.CHARGES},mode:MODE.GET})},this.customerCards=function(a){return c.makeRequest({token:{primary:a},endpoint:{primary:ENDPOINT.CUSTOMER,secondary:ENDPOINT.CARDS},mode:MODE.GET})},this.createCustomerCard=function(a,b){return c.makeRequest({body:a,token:{primary:b},endpoint:{primary:ENDPOINT.CUSTOMER,secondary:ENDPOINT.CARDS},mode:MODE.POST})},this.deleteCustomerCard=function(a,b){return c.makeRequest({token:{primary:a,secondary:b},endpoint:{primary:ENDPOINT.CUSTOMER,secondary:ENDPOINT.CARDS},mode:MODE.DELETE})},this.createCharge=function(a){return c.makeRequest({body:a,endpoint:{primary:ENDPOINT.CHARGES},mode:MODE.POST})},this.createCard=function(a){return c.makeRequest({body:a,endpoint:{primary:ENDPOINT.CARDS},mode:MODE.POST})},this.fetchAllPlans=function(a){return c.makeRequest({body:a,endpoint:{primary:ENDPOINT.PLANS},mode:MODE.GET})},this.fetchPlan=function(a){var b=a.token;return c.makeRequest({token:{primary:b},endpoint:{primary:ENDPOINT.PLANS},mode:MODE.GET})},this.createSubscription=function(a){var b=a.customerToken,d=a.planToken,e=_objectWithoutProperties(a,["customerToken","planToken"]);return c.makeRequest({body:_extends({customer_token:b,plan_token:d},e),endpoint:{primary:ENDPOINT.SUBSCRIPTIONS},mode:MODE.POST})},this.fetchSubscription=function(a){var b=a.token;return c.makeRequest({token:{primary:b},endpoint:{primary:ENDPOINT.SUBSCRIPTIONS},mode:MODE.GET})},this.cancelSubscription=function(a){var b=a.token;return c.makeRequest({token:{primary:b},endpoint:{primary:ENDPOINT.SUBSCRIPTIONS},mode:MODE.DELETE})},this.key=b.key,this.live=b.live,this.setApiUrl()};exports.default=PinAPI; |
@@ -281,4 +281,17 @@ import request from "request"; | ||
}; | ||
cancelSubscription = body => { | ||
const { token } = body; | ||
return this.makeRequest({ | ||
token: { | ||
primary: token | ||
}, | ||
endpoint: { | ||
primary: ENDPOINT.SUBSCRIPTIONS | ||
}, | ||
mode: MODE.DELETE | ||
}); | ||
}; | ||
} | ||
export default PinAPI; |
{ | ||
"name": "pin-api", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Pin Payments API wrapper", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28100
811