Skip to content

Commit

Permalink
Merge pull request #35 from square/deanpapastrat/allow-specifying-hea…
Browse files Browse the repository at this point in the history
…d-url

Add support for specifying URL the payment form loads from
  • Loading branch information
deanpapastrat authored Aug 20, 2019
2 parents f21998f + 5308867 commit 2c9a1af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
22 changes: 20 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,29 @@ const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');
const join = require('path').join;

function jsUrlForEnvironment(config) {
if (config.squarePaymentForm) {
if (config.squarePaymentForm.jsUrl) {
return config.squarePaymentForm.jsUrl;
} else if (config.squarePaymentForm.environment === 'sandbox') {
return 'https://js.squareupsandbox.com/v2/paymentform';
}
}

// If we're in development or test mode, we probably want to use sandbox instead
// of production.
if (config.environment === 'development' || config.environment === 'test') {
return 'https://js.squareupsandbox.com/v2/paymentform';
} else {
return 'https://js.squareup.com/v2/paymentform';
}
}

module.exports = {
name: require('./package').name,
contentFor(type) {
contentFor(type, config) {
if (type === 'head') {
return '<script type="text/javascript" src="https://js.squareup.com/v2/paymentform"></script>';
return `<script type="text/javascript" src="${jsUrlForEnvironment(config)}"></script>`;
}
},
treeForPublic: function() {
Expand Down
5 changes: 5 additions & 0 deletions tests/dummy/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ module.exports = function(environment) {
if (environment === 'production') {
// Allow ember-cli-addon-docs to update the rootURL in compiled assets
ENV.rootURL = 'ADDON_DOCS_ROOT_URL';

// Use sandbox mode in production since we aren't taking prod payments
ENV.squarePaymentForm = {
environment: 'sandbox'
};
// here you can enable a production-specific feature
}

Expand Down

0 comments on commit 2c9a1af

Please sign in to comment.