Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@salla.sa/applepay

Package Overview
Dependencies
Maintainers
44
Versions
186
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@salla.sa/applepay - npm Package Compare versions

Comparing version 1.0.29 to 1.0.30

2

package.json
{
"name": "@salla.sa/applepay",
"version": "1.0.29",
"version": "1.0.30",
"description": "Salla Apple Pay",

@@ -5,0 +5,0 @@ "main": "dist/app.js",

@@ -6,3 +6,2 @@ import Http from './http';

window.Salla.Payments = window.Salla.Payments || {};
/**

@@ -42,3 +41,3 @@ * Full Example

*/
window.Salla.Payments.ApplePay = function() {
window.Salla.Payments.ApplePay = function () {

@@ -54,3 +53,4 @@ const session = null;

return {
init: function() {
init: function () {
window.isLegacyTheme = window.$ && ['theme_1', 'theme_2', 'theme_3', 'theme_4', 'theme_5', 'theme_6', 'default'].includes(Salla?.theme?.name);
// init the helpers

@@ -60,12 +60,14 @@ document.removeEventListener('payments::apple-pay.start-transaction', window.Salla.Payments.ApplePay.startSession);

if (!(window.ApplePaySession && ApplePaySession.canMakePayments())) {
$('[data-show-if-apple-pay-supported]').hide();
if (window.ApplePaySession && ApplePaySession.canMakePayments()) {
return;
}
document.querySelectorAll('data-show-if-apple-pay-supported').forEach(btn => btn.style.display = 'none');
},
initDefault: function() {
initDefault: function () {
let _this = window.Salla.Payments.ApplePay;
if (!_this.detail.onError) {
_this.detail.onError = function(message) {
_this.detail.onError = function (message) {
laravel.alert(message);

@@ -96,3 +98,3 @@ };

startSession: function(event) {
startSession: function (event) {
console.log('start session : payments::apple-pay.start-transaction');

@@ -122,4 +124,4 @@

_this.total = {
type: 'final',
label: label,
type : 'final',
label : label,
amount: _this.detail.amount

@@ -129,10 +131,10 @@ };

_this.request = {
countryCode: 'SA',
currencyCode: _this.detail.currency || 'SAR',
countryCode : 'SA',
currencyCode : _this.detail.currency || 'SAR',
requiredShippingContactFields: _this.detail.requiredShippingContactFields ? _this.detail.requiredShippingContactFields : [],
merchantCapabilities: ['supports3DS'],
supportedNetworks: _this.detail.supportedNetworks || supportedNetworks,
total: _this.total,
shippingContact: _this.detail.shippingContact ? _this.detail.shippingContact : {},
shippingMethods: _this.detail.shippingMethods && _this.detail.shippingMethods.length ? _this.mappingShippingMethods(event.detail.shippingMethods) : []
merchantCapabilities : ['supports3DS'],
supportedNetworks : _this.detail.supportedNetworks || supportedNetworks,
total : _this.total,
shippingContact : _this.detail.shippingContact ? _this.detail.shippingContact : {},
shippingMethods : _this.detail.shippingMethods && _this.detail.shippingMethods.length ? _this.mappingShippingMethods(event.detail.shippingMethods) : []
};

@@ -201,3 +203,3 @@

Http.post(_this.detail.validateMerchant.url.replace('{id}', _this.id), {
amount: _this.detail.amount,
amount : _this.detail.amount,
validation_url: event.validationURL,

@@ -216,3 +218,3 @@ payment_method: 'apple_pay'

}
_this.session.completeMerchantValidation(data.data);

@@ -260,36 +262,36 @@

Http.post(_this.detail.shippingContactSelected.url.replace('{id}', _this.id),
{
'country': event.shippingContact.country,
'city': event.shippingContact.locality,
'local': event.shippingContact.subLocality,
'description': event.shippingContact.subAdministrativeArea,
'street': event.shippingContact.administrativeArea,
'country_code': event.shippingContact.countryCode,
'postal_code': event.shippingContact.postalCode
},
({data}) => {
if (typeof _this.detail.shippingContactSelected.onSuccess === 'function') {
_this.detail.shippingContactSelected.onSuccess(data);
}
{
'country' : event.shippingContact.country,
'city' : event.shippingContact.locality,
'local' : event.shippingContact.subLocality,
'description' : event.shippingContact.subAdministrativeArea,
'street' : event.shippingContact.administrativeArea,
'country_code': event.shippingContact.countryCode,
'postal_code' : event.shippingContact.postalCode
},
({data}) => {
if (typeof _this.detail.shippingContactSelected.onSuccess === 'function') {
_this.detail.shippingContactSelected.onSuccess(data);
}
_this.address_id = data.data.address_id;
_this.shipping_methods = data.data.shipping_methods;
_this.address_id = data.data.address_id;
_this.shipping_methods = data.data.shipping_methods;
if (!_this.shipping_methods || (_this.shipping_methods && !_this.shipping_methods.length)) {
reject('لايوجد شركات شحن لهذا العنوان');
}
if (!_this.shipping_methods || (_this.shipping_methods && !_this.shipping_methods.length)) {
reject('لايوجد شركات شحن لهذا العنوان');
}
resolve(data);
resolve(data);
}, ({response}) => {
console.log(response);
// _this.abortSession();
if (typeof _this.detail.shippingContactSelected.onFailed === 'function') {
_this.detail.shippingContactSelected.onFailed(response);
}
_this.session.completeShippingContactSelection({
'newTotal': _this.total,
'errors': [new window.ApplePayError('shippingContactInvalid', 'locality', response.data.error.message)]
});
}, ({response}) => {
console.log(response);
// _this.abortSession();
if (typeof _this.detail.shippingContactSelected.onFailed === 'function') {
_this.detail.shippingContactSelected.onFailed(response);
}
_this.session.completeShippingContactSelection({
'newTotal': _this.total,
'errors' : [new window.ApplePayError('shippingContactInvalid', 'locality', response.data.error.message)]
});
});

@@ -301,14 +303,14 @@ }).then(() => {

_this.session.completeShippingContactSelection(
{
'newTotal': _this.total,
'newShippingMethods': _this.mappingShippingMethods(_this.shipping_methods)
}
{
'newTotal' : _this.total,
'newShippingMethods': _this.mappingShippingMethods(_this.shipping_methods)
}
);
}).catch(function(error) {
}).catch(function (error) {
console.log(error);
_this.session.completeShippingContactSelection(
{
'newTotal': _this.total,
'errors': [new window.ApplePayError('shippingContactInvalid', 'locality', error)]
});
{
'newTotal': _this.total,
'errors' : [new window.ApplePayError('shippingContactInvalid', 'locality', error)]
});
//_this.abortSession();

@@ -331,4 +333,4 @@ });

_this.selectApplePayShippingMethod(
shipping_ids[0],
typeof shipping_ids[1] === 'undefined' ? null : shipping_ids[1]
shipping_ids[0],
typeof shipping_ids[1] === 'undefined' ? null : shipping_ids[1]
);

@@ -340,3 +342,3 @@ resolve();

}).catch(function(error) {
}).catch(function (error) {
console.log(error);

@@ -383,8 +385,28 @@ _this.abortSession();

let _this = window.Salla.Payments.ApplePay;
const url = _this.detail.recalculateTotal.url.replace('{id}', _this.id);
if (!window.isLegacyTheme) {
//twilight
try {
let data = salla.api.payment.recalculateTotal(url);
_this.total = Object.assign({}, _this.total, {
amount: data.data.initial_data.cart.total
});
let total = _this.total;
_this.request = Object.assign({}, _this.request, {total});
} catch (error) {
console.error(error);
// expected output: ReferenceError: nonExistentFunction is not defined
// Note - error messages will vary depending on browser
}
return;
}
//we are sure that this is called in a legacy theme
$.ajax({
url: _this.detail.recalculateTotal.url.replace('{id}', _this.id),
method: 'GET',
async: false,
success: function(data) {
url : url,
method : 'GET',
async : false,
success: function (data) {
_this.total = Object.assign({}, _this.total, {

@@ -398,3 +420,3 @@ amount: data.data.initial_data.cart.total

},
error: function(e) {
error : function (e) {
console.log('Recalculate Total Failed');

@@ -409,14 +431,32 @@ console.log(response);

console.log('select shipping method ', 'company_id : ' + company_id, 'private_company_id: ' + private_company_id);
let url = _this.detail.shippingMethodSelected.url.replace('{id}', _this.id)
let payload = {
address_id : _this.address_id,
company_id : company_id,
private_company_id: private_company_id,
payment_method : 'apple_pay'
};
if (!window.isLegacyTheme) {
try {
let data = salla.api.payment.selectShippingMethod(url, payload)
if (typeof _this.detail.shippingMethodSelected.onSuccess === 'function') {
_this.detail.shippingMethodSelected.onSuccess(data);
}
_this.recalculateTotal();
} catch (error) {
if (typeof _this.detail.shippingMethodSelected.onFailed === 'function') {
_this.detail.shippingMethodSelected.onFailed(error);
}
}
return;
}
//we are sure that this is called in a legacy theme
$.ajax({
url: _this.detail.shippingMethodSelected.url.replace('{id}', _this.id),
method: 'POST',
data: {
address_id: _this.address_id,
company_id: company_id,
private_company_id: private_company_id,
payment_method: 'apple_pay'
},
async: false,
success: function(data) {
url : url,
method : 'POST',
data : payload,
async : false,
success: function (data) {
if (typeof _this.detail.shippingMethodSelected.onSuccess === 'function') {

@@ -427,3 +467,3 @@ _this.detail.shippingMethodSelected.onSuccess(data);

},
error: function(response) {
error : function (response) {
// _this.abortSession();

@@ -439,3 +479,3 @@ if (typeof _this.detail.shippingMethodSelected.onFailed === 'function') {

return methods.map(function(method) {
return methods.map(function (method) {
let identifier = method.ship_id.toString();

@@ -447,5 +487,5 @@

return {
'label': method.shipping_title,
'amount': method.enable_free_shipping ? 0 : method.ship_cost,
'detail': '',
'label' : method.shipping_title,
'amount' : method.enable_free_shipping ? 0 : method.ship_cost,
'detail' : '',
'identifier': identifier

@@ -452,0 +492,0 @@ };

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