Skip to content

Commit

Permalink
Merge branch 'release/0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvoon committed Mar 24, 2020
2 parents 7d25019 + 31b973d commit 69853b0
Show file tree
Hide file tree
Showing 20 changed files with 2,301 additions and 385 deletions.
65 changes: 65 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"root": true,
"extends": [
"airbnb-base",
"plugin:prettier/recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"env": {
"browser": true,
"es6": true,
"node": true,
"jest": true
},
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"import/first": "off",
"import/order": [
"error",
{
"groups": [
"builtin",
"external",
"parent",
"sibling",
"index"
]
}
],
"jsx-a11y/anchor-is-valid": "off",
"no-console": [
"error",
{
"allow": [
"error"
]
}
],
"no-param-reassign": "off",
"no-return-assign": [
"error",
"except-parens"
],
"no-underscore-dangle": [
"error",
{
"allow": [
"_destroy",
"_payment_method"
]
}
],
"import/prefer-default-export": "off",
"camelcase": "off",
"class-methods-use-this": "off",
"max-len": "off"
}
}
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
20 changes: 18 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import { Submarine } from './src/submarine';
import { SubmarinePaymentMethodStep } from "./src/checkout/submarine_payment_method_step";
import { SubmarinePaymentMethodStep } from './src/checkout/submarine_payment_method_step';
import { SubmarineThankYouStep } from './src/checkout/submarine_thank_you_step';
import { BraintreeCreditCardShopPaymentMethod } from './src/checkout/payment_methods/shop_payment_methods/braintree_credit_card_shop_payment_method';
import { BraintreeApplePayShopPaymentMethod } from './src/checkout/payment_methods/shop_payment_methods/braintree_apple_pay_shop_payment_method';
import { CybersourceCreditCardShopPaymentMethod } from './src/checkout/payment_methods/shop_payment_methods/cybersource_credit_card_shop_payment_method';
import { StripeCreditCardShopPaymentMethod } from './src/checkout/payment_methods/shop_payment_methods/stripe_credit_card_shop_payment_method';
import { KomojuCreditCardShopPaymentMethod } from './src/checkout/payment_methods/shop_payment_methods/komoju_credit_card_payment_method';
import { SubmarineBankTransferShopPaymentMethod } from './src/checkout/payment_methods/shop_payment_methods/submarine_bank_transfer_payment_method';

export { Submarine, SubmarinePaymentMethodStep, SubmarineThankYouStep };
export {
Submarine,
SubmarinePaymentMethodStep,
SubmarineThankYouStep,
BraintreeCreditCardShopPaymentMethod,
BraintreeApplePayShopPaymentMethod,
CybersourceCreditCardShopPaymentMethod,
StripeCreditCardShopPaymentMethod,
KomojuCreditCardShopPaymentMethod,
SubmarineBankTransferShopPaymentMethod
};
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"name": "@discolabs/submarine-js",
"version": "0.0.26",
"version": "0.1.0",
"description": "Javascript client library for Submarine.",
"main": "index.js",
"author": "Gavin Ballard",
"scripts": {
"lint": "eslint . -c .eslintrc"
},
"repository": {
"type": "git",
"url": "https://github.com/discolabs/submarine-js.git"
Expand All @@ -14,6 +17,16 @@
],
"dependencies": {
"@discolabs/custard-js": "^0.0.4",
"lodash": "^4.17.15",
"payform": "^1.4.0"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-prettier": "^3.1.2",
"prettier": "^1.19.1"
}
}
77 changes: 49 additions & 28 deletions src/api_client/api_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const API_METHODS = {
},
duplicate_subscription: {
http_method: POST,
endpoint: '/customers/{{ customer_id }}/subscriptions/{{ id }}/duplicate.json'
endpoint:
'/customers/{{ customer_id }}/subscriptions/{{ id }}/duplicate.json'
},
update_subscription: {
http_method: PUT,
Expand Down Expand Up @@ -54,23 +55,22 @@ const API_METHODS = {
* @param context
* @returns {string}
*/
const getMethodUrl = (api_url, method, context) => {
return Object.entries(context).reduce((method_url, contextValue) => {
const [k , v] = contextValue;
const getMethodUrl = (api_url, method, context) =>
Object.entries(context).reduce((method_url, contextValue) => {
const [k, v] = contextValue;
return method_url.replace(new RegExp(`{{ ${k} }}`, 'g'), v);
}, [api_url, API_METHODS[method].endpoint].join(''));
};

/**
* Return a querystring that can be appended to an API endpoint.
*
* @params params
* @returns {string}
*/
const buildQueryString = (params) => {
const buildQueryString = params => {
const queryString = Object.keys(params)
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
.join("&");
.join('&');

return `?${queryString}`;
};
Expand All @@ -82,9 +82,7 @@ const buildQueryString = (params) => {
* @param method
* @returns {string}
*/
const getMethodHttpMethod = (method) => {
return API_METHODS[method].http_method;
};
const getMethodHttpMethod = method => API_METHODS[method].http_method;

/**
* Return the appropriate request payload for the given HTTP method and
Expand All @@ -102,7 +100,6 @@ const getMethodPayload = (http_method, data) => {
};

export class ApiClient {

constructor(api_url, authentication, context) {
this.api_url = api_url;
this.authentication = authentication;
Expand All @@ -119,59 +116,83 @@ export class ApiClient {
method: http_method,
mode: 'cors',
headers: {
"Content-Type": "application/json; charset=utf-8"
'Content-Type': 'application/json; charset=utf-8'
},
body: payload
}).then((response) => {
return response.json();
}).then((json) => {
callback && callback(json.data);
});
})
.then(response => response.json())
.then(json => callback && callback(json.data));
}

buildQueryParams(http_method, data) {
return http_method === GET ? Object.assign(this.authentication, data) : this.authentication;
return http_method === GET
? Object.assign(this.authentication, data)
: this.authentication;
}

getPaymentMethods(callback) {
return this.execute('get_payment_methods', {}, this.context, callback);
}

createPaymentMethod(customer_payment_method, callback) {
return this.execute('create_payment_method', customer_payment_method, this.context, callback);
return this.execute(
'create_payment_method',
customer_payment_method,
this.context,
callback
);
}

removePaymentMethod(id, callback) {
const context = Object.assign({}, this.context, { id });
const context = { ...this.context, id };
return this.execute('remove_payment_method', {}, context, callback);
}

getSubscriptions(callback, params = {}) {
return this.execute('get_subscriptions', Object.assign({}, params), this.context, callback);
return this.execute(
'get_subscriptions',
{ ...params },
this.context,
callback
);
}

updateSubscription(id, subscription, callback) {
const context = Object.assign({}, this.context, { id });
const context = { ...this.context, id };
return this.execute('update_subscription', subscription, context, callback);
}

cancelSubscription(id, callback) {
const context = Object.assign({}, this.context, { id });
const context = { ...this.context, id };
return this.execute('cancel_subscription', {}, context, callback);
}

duplicateSubscription(id, callback) {
const context = Object.assign({}, this.context, { id });
const context = { ...this.context, id };
return this.execute('duplicate_subscription', {}, context, callback);
}

generatePaymentProcessorClientToken(payment_processor, callback) {
const payload = { data: { type: 'payment_processor_client_token', attributes: { payment_processor } } };
return this.execute('generate_payment_processor_client_token', payload, this.context, callback);
const payload = {
data: {
type: 'payment_processor_client_token',
attributes: { payment_processor }
}
};
return this.execute(
'generate_payment_processor_client_token',
payload,
this.context,
callback
);
}

createPreliminaryPaymentMethod(preliminary_payment_method, callback) {
return this.execute('create_preliminary_payment_method', preliminary_payment_method, this.context, callback);
return this.execute(
'create_preliminary_payment_method',
preliminary_payment_method,
this.context,
callback
);
}

}
24 changes: 17 additions & 7 deletions src/checkout/payment_methods/customer_payment_methods.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CustomerPaymentMethod } from "./customer_payment_methods/customer_payment_method";
import { CustomerPaymentMethod } from './customer_payment_methods/customer_payment_method';

/**
* Given a shop payment method type, return the appropriate payment method
Expand All @@ -7,9 +7,7 @@ import { CustomerPaymentMethod } from "./customer_payment_methods/customer_payme
* @param customerPaymentMethod
* @returns {CustomerPaymentMethod}
*/
const getCustomerPaymentMethodClass = (customerPaymentMethod) => {
return CustomerPaymentMethod;
};
const getCustomerPaymentMethodClass = () => CustomerPaymentMethod;

/**
* Given a set of payment method options and a shop payment method type, return
Expand All @@ -21,7 +19,19 @@ const getCustomerPaymentMethodClass = (customerPaymentMethod) => {
* @param customerPaymentMethod
* @returns {CustomerPaymentMethod}
*/
export const createCustomerPaymentMethod = ($, options, translations, customerPaymentMethod) => {
const customerPaymentMethodClass = getCustomerPaymentMethodClass(customerPaymentMethod);
return new customerPaymentMethodClass($, options, translations, customerPaymentMethod);
export const createCustomerPaymentMethod = (
$,
options,
translations,
customerPaymentMethod
) => {
const CustomerPaymentMethodClass = getCustomerPaymentMethodClass(
customerPaymentMethod
);
return new CustomerPaymentMethodClass({
$,
options,
translations,
data: customerPaymentMethod
});
};
Loading

0 comments on commit 69853b0

Please sign in to comment.