Skip to content

Commit

Permalink
feat [PAR-24]: Add ability to pass custom payment URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarwlar authored and k-pushkarev committed Apr 22, 2020
1 parent 377fbd7 commit 6f082df
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 54 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.2.0 - 2020-04-17

- [feature] Add ability to pass custom payment URL

## 1.1.0 - 2019-12-12

- [feature] Remove lodash and JQuery from project
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Features:

#### Linking to Xsolla CDN

Script is located on our CDN and is available here: [https://cdn.xsolla.net/embed/paystation/1.1.0/widget.min.js](https://cdn.xsolla.net/embed/paystation/1.1.0/widget.min.js). Use this URL to integrate script on your website.
Script is located on our CDN and is available here: [https://cdn.xsolla.net/embed/paystation/1.2.0/widget.min.js](https://cdn.xsolla.net/embed/paystation/1.2.0/widget.min.js). Use this URL to integrate script on your website.

#### Installing with Bower

Expand All @@ -37,7 +37,7 @@ $ bower install xsolla-paystation-widget
var s = document.createElement('script');
s.type = "text/javascript";
s.async = true;
s.src = "//cdn.xsolla.net/embed/paystation/1.1.0/widget.min.js";
s.src = "//cdn.xsolla.net/embed/paystation/1.2.0/widget.min.js";
s.addEventListener('load', function (e) {
XPayStationWidget.init(options);
}, false);
Expand All @@ -49,7 +49,7 @@ $ bower install xsolla-paystation-widget
#### Synchronous loading (blocks content)

``` javascript
<script src="//cdn.xsolla.net/embed/paystation/1.1.0/widget.min.js"></script>
<script src="//cdn.xsolla.net/embed/paystation/1.2.0/widget.min.js"></script>
<script>
XPayStationWidget.init({
access_token: 'abcdef1234567890abcdef1234567890'
Expand Down
56 changes: 32 additions & 24 deletions dist/widget.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dist/widget.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/widget.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "PayStation 3 Integration Widget",
"dependencies": {},
"devDependencies": {
"bower": "1.4.1",
"bower": "1.8.8",
"browser-sync": "2.7.13",
"browserify": "10.2.4",
"gulp": "3.9.0",
Expand Down
37 changes: 21 additions & 16 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var Device = require('./device');

module.exports = (function () {
function ready(fn) {
if (document.readyState != 'loading'){
if (document.readyState !== 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
Expand Down Expand Up @@ -44,6 +44,7 @@ module.exports = (function () {
childWindow: {},
host: 'secure.xsolla.com'
};
var SANDBOX_PAYSTATION_URL = 'https://sandbox-secure.xsolla.com/paystation2/?';
var EVENT_NAMESPACE = '.xpaystation-widget';
var ATTR_PREFIX = 'data-xpaystation-widget-open';

Expand All @@ -52,14 +53,27 @@ module.exports = (function () {
App.prototype.isInitiated = false;
App.prototype.eventObject = Helpers.addEventObject(this);

App.prototype.getPaystationUrl = function () {
var SANDBOX_PAYSTATION_URL = 'https://sandbox-secure.xsolla.com/paystation2/?';
return this.config.sandbox ? SANDBOX_PAYSTATION_URL : 'https://' + this.config.host + '/paystation2/?';
App.prototype.getPaymentUrl = function () {
if (this.config.payment_url) {
return this.config.payment_url;
}

const query = {};
if (this.config.access_token) {
query.access_token = this.config.access_token;
} else {
query.access_data = JSON.stringify(this.config.access_data);
}

const urlWithoutQueryParams = this.config.sandbox ?
SANDBOX_PAYSTATION_URL :
'https://' + this.config.host + '/paystation2/?';
return urlWithoutQueryParams + Helpers.param(query);
};

App.prototype.checkConfig = function () {
if (Helpers.isEmpty(this.config.access_token) && Helpers.isEmpty(this.config.access_data)) {
this.throwError('No access token given');
if (Helpers.isEmpty(this.config.access_token) && Helpers.isEmpty(this.config.access_data) && Helpers.isEmpty(this.config.payment_url)) {
this.throwError('No access token or access data or payment URL given');
}

if (!Helpers.isEmpty(this.config.access_data) && typeof this.config.access_data !== 'object') {
Expand Down Expand Up @@ -148,16 +162,7 @@ module.exports = (function () {
}
}).bind(this);

var query = {};
if (this.config.access_token) {
query.access_token = this.config.access_token;
} else {
query.access_data = JSON.stringify(this.config.access_data);
}



var url = this.getPaystationUrl() + Helpers.param(query);
var url = this.getPaymentUrl();
var that = this;

function handleStatus(event) {
Expand Down
15 changes: 9 additions & 6 deletions src/lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ module.exports = (function () {
var lightBoxSpinnerElement = lightBoxElement.querySelector('.' + CLASS_PREFIX + '-spinner');

var psDimensions = {
width: '0px',
height: '0px'
width: withDefaultPXUnit(MIN_PS_DIMENSIONS.width),
height: withDefaultPXUnit(MIN_PS_DIMENSIONS.height)
};

function withDefaultPXUnit(value) {
Expand Down Expand Up @@ -228,6 +228,10 @@ module.exports = (function () {
}
};

if (options.width && options.height) {
lightBoxResize = Helpers.once(lightBoxResize.bind(this));
}

function outerWidth(el) {
var width = el.offsetWidth;
var style = getComputedStyle(el);
Expand Down Expand Up @@ -275,8 +279,9 @@ module.exports = (function () {

var loadTimer;
lightBoxIframeElement.addEventListener('load', function handleLoad(event) {
var timeout = !options.width || !options.height ? 30000 : 1000; //30000 if psDimensions will not arrive
var timeout = !(options.width && options.height) ? (options.resizeTimeout || 30000) : 1000; // 30000 if psDimensions will not arrive and custom timeout is not provided
loadTimer = global.setTimeout(function () {
lightBoxResize();
showContent();
}, timeout);
lightBoxIframeElement.removeEventListener('load', handleLoad);
Expand All @@ -289,6 +294,7 @@ module.exports = (function () {
this.message = new PostMessage(iframeWindow);
if (options.width && options.height) {
this.message.on('dimensions', (function () {
lightBoxResize();
showContent();
}));
} else {
Expand Down Expand Up @@ -333,9 +339,6 @@ module.exports = (function () {
that.off('close', handleClose);
});

if (options.width && options.height) {
lightBoxResize();
}
showSpinner();
hideScrollbar();
this.triggerEvent('open');
Expand Down
2 changes: 1 addition & 1 deletion src/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = '1.0.6';
module.exports = '1.2.0';

0 comments on commit 6f082df

Please sign in to comment.