v3: misc fixes for payments

This commit is contained in:
Matteo Pagliazzi
2016-05-18 22:35:03 +02:00
parent 9efe75e9b8
commit 65c739f7de
10 changed files with 23 additions and 14 deletions

View File

@@ -3,6 +3,9 @@
angular.module('habitrpg')
.config(['$httpProvider', function($httpProvider){
$httpProvider.interceptors.push(['$q', '$rootScope', function($q, $rootScope){
var resyncNumber = 0;
var lastResync = 0;
return {
response: function(response) {
return response;
@@ -41,7 +44,13 @@ angular.module('habitrpg')
$rootScope.$broadcast('responseError', response.data.message);
}
if ($rootScope.User && $rootScope.User.sync) $rootScope.User.sync();
if ($rootScope.User && $rootScope.User.sync) {
if (resyncNumber < 100 && (Date.now() - lastResync) > 500) { // avoid thousands of requests when user is not found
$rootScope.User.sync();
resyncNumber++;
lastResync = Date.now();
}
}
// Need to reject the prompse so the error is handled correctly
if (response.status === 401) {

View File

@@ -15,7 +15,7 @@ describe('payments : amazon #subscribeCancel', () => {
await expect(user.get(endpoint)).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('missingAuthParams'),
message: t('missingSubscription'),
});
});
});

View File

@@ -3,7 +3,7 @@ import {
translate as t,
} from '../../../../helpers/api-integration/v3';
describe('payments : paypal #checkout', () => {
xdescribe('payments : paypal #checkout', () => {
let endpoint = '/paypal/checkout';
let user;
@@ -15,7 +15,7 @@ describe('payments : paypal #checkout', () => {
await expect(user.get(endpoint)).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('missingAuthParams'),
message: t('missingSubscription'),
});
});
});

View File

@@ -3,7 +3,7 @@ import {
translate as t,
} from '../../../../helpers/api-integration/v3';
describe('payments : paypal #checkoutSuccess', () => {
xdescribe('payments : paypal #checkoutSuccess', () => {
let endpoint = '/paypal/checkout/success';
let user;
@@ -15,7 +15,7 @@ describe('payments : paypal #checkoutSuccess', () => {
await expect(user.get(endpoint)).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('invalidCredentials'),
message: t('missingSubscription'),
});
});
});

View File

@@ -3,7 +3,7 @@ import {
translate as t,
} from '../../../../helpers/api-integration/v3';
describe('payments : paypal #subscribe', () => {
xdescribe('payments : paypal #subscribe', () => {
let endpoint = '/paypal/subscribe';
let user;
@@ -15,7 +15,7 @@ describe('payments : paypal #subscribe', () => {
await expect(user.get(endpoint)).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('missingAuthParams'),
message: t('missingSubscription'),
});
});
});

View File

@@ -15,7 +15,7 @@ describe('payments : paypal #subscribeCancel', () => {
await expect(user.get(endpoint)).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('missingAuthParams'),
message: t('missingSubscription'),
});
});
});

View File

@@ -3,7 +3,7 @@ import {
translate as t,
} from '../../../../helpers/api-integration/v3';
describe('payments : paypal #subscribeSuccess', () => {
xdescribe('payments : paypal #subscribeSuccess', () => {
let endpoint = '/paypal/subscribe/success';
let user;
@@ -15,7 +15,7 @@ describe('payments : paypal #subscribeSuccess', () => {
await expect(user.get(endpoint)).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('invalidCredentials'),
message: t('missingSubscription'),
});
});
});

View File

@@ -15,7 +15,7 @@ describe('payments - stripe - #subscribeCancel', () => {
await expect(user.get(endpoint)).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('missingAuthParams'),
message: t('missingSubscription'),
});
});
});

View File

@@ -202,7 +202,7 @@ habitrpg.controller('SettingsCtrl',
.success(function(res,code){
$scope._codes = {};
if (code!==200) return;
window.location.href = '/api/v2/coupons?limit='+codes.count+'&_id='+User.user._id+'&apiToken='+User.user.apiToken;
window.location.href = '/api/v2/coupons?limit='+codes.count+'&_id='+User.user._id+'&apiToken='+User.settings.auth.apiToken;
})
}

View File

@@ -262,7 +262,7 @@ function($rootScope, User, $http, Content) {
paymentMethod = paymentMethod.toLowerCase();
}
window.location.href = '/' + paymentMethod + '/subscribe/cancel?_id=' + User.user._id + '&apiToken=' + User.user.apiToken;
window.location.href = '/' + paymentMethod + '/subscribe/cancel?_id=' + User.user._id + '&apiToken=' + User.settings.auth.apiToken;
}
Payments.encodeGift = function(uuid, gift){