@posiwise/common-services 0.2.21 → 0.2.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -29,7 +29,8 @@ import { NgbDateParserFormatter } from '@ng-bootstrap/ng-bootstrap';
|
|
|
29
29
|
import { webSocket } from 'rxjs/webSocket';
|
|
30
30
|
import { StatusCodes } from 'http-status-codes';
|
|
31
31
|
import { fromError } from 'stacktrace-js';
|
|
32
|
-
import { createErrorHandler, init
|
|
32
|
+
import { createErrorHandler, init } from '@sentry/angular';
|
|
33
|
+
import { withScope, captureException } from '@sentry/core';
|
|
33
34
|
|
|
34
35
|
class ScriptLoaderService {
|
|
35
36
|
constructor(document) {
|
|
@@ -802,6 +803,7 @@ class UserService {
|
|
|
802
803
|
this.toast = toast;
|
|
803
804
|
this.endpoint = USER_PATH;
|
|
804
805
|
this.isTosModalOpen = false;
|
|
806
|
+
this.isSecondaryPaymentModalOpen = false;
|
|
805
807
|
}
|
|
806
808
|
getUserState() {
|
|
807
809
|
return this.store.select(getUser);
|
|
@@ -813,8 +815,51 @@ class UserService {
|
|
|
813
815
|
this.router.navigate(['settings/security']);
|
|
814
816
|
}
|
|
815
817
|
this.checkAndHandleTosAcceptance(data);
|
|
818
|
+
this.checkAndHandleSecondaryPayment(data);
|
|
816
819
|
}));
|
|
817
820
|
}
|
|
821
|
+
/**
|
|
822
|
+
* Hard-gate the user when their active product requires a Braintree
|
|
823
|
+
* (secondary) payment method and they don't have one registered yet.
|
|
824
|
+
* Pattern mirrors checkAndHandleTosAcceptance — a non-dismissable
|
|
825
|
+
* SweetAlert2 modal that takes the user to the update-payment route.
|
|
826
|
+
* See main-api ticket #922.
|
|
827
|
+
*/
|
|
828
|
+
checkAndHandleSecondaryPayment(user) {
|
|
829
|
+
if (!user || this.isSecondaryPaymentModalOpen) {
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
const status = user.payment_methods_status;
|
|
833
|
+
if (!status?.requires_secondary_payment) {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
const subId = status.failing_subscription_id;
|
|
837
|
+
const productId = status.failing_product_id;
|
|
838
|
+
if (!subId || !productId) {
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
this.isSecondaryPaymentModalOpen = true;
|
|
842
|
+
swal.fire({
|
|
843
|
+
icon: 'warning',
|
|
844
|
+
title: 'Secondary payment method required',
|
|
845
|
+
html: 'Your subscription requires a backup payment method. Click <b>Add Now</b> to register a secondary card — you cannot continue using the app until this is set up.',
|
|
846
|
+
confirmButtonText: 'Add Now',
|
|
847
|
+
allowOutsideClick: false,
|
|
848
|
+
allowEscapeKey: false,
|
|
849
|
+
showCancelButton: false,
|
|
850
|
+
reverseButtons: false,
|
|
851
|
+
focusConfirm: true
|
|
852
|
+
}).then(() => {
|
|
853
|
+
this.isSecondaryPaymentModalOpen = false;
|
|
854
|
+
this.router.navigate([
|
|
855
|
+
'/account/subscriptions',
|
|
856
|
+
subId,
|
|
857
|
+
'product',
|
|
858
|
+
productId,
|
|
859
|
+
'update-payment'
|
|
860
|
+
]);
|
|
861
|
+
});
|
|
862
|
+
}
|
|
818
863
|
/**
|
|
819
864
|
* Ensure the current user has accepted the latest Terms of Service for this domain.
|
|
820
865
|
* If the domain has a newer TOS version than the user's accepted timestamp, a blocking
|
|
@@ -1997,6 +2042,17 @@ class SubscriptionService {
|
|
|
1997
2042
|
updateCardDetails(data, subscription_id) {
|
|
1998
2043
|
return this.api.post(`/subscriptions/${subscription_id}/update_card`, data);
|
|
1999
2044
|
}
|
|
2045
|
+
getPaymentMethods(subscriptionId) {
|
|
2046
|
+
return this.api.get(`/subscriptions/${subscriptionId}/payment_methods`);
|
|
2047
|
+
}
|
|
2048
|
+
getBraintreeClientToken(subscriptionId) {
|
|
2049
|
+
return this.api.get(`/subscriptions/${subscriptionId}/braintree_client_token`);
|
|
2050
|
+
}
|
|
2051
|
+
registerBraintreePaymentMethod(subscriptionId, paymentMethodNonce) {
|
|
2052
|
+
return this.api.post(`/subscriptions/${subscriptionId}/braintree_payment_method`, {
|
|
2053
|
+
payment_method_nonce: paymentMethodNonce
|
|
2054
|
+
});
|
|
2055
|
+
}
|
|
2000
2056
|
getEnterpriseInsight(subscriptionId, starting_at, ending_at) {
|
|
2001
2057
|
return this.api.getWithParams(`/subscriptions/${subscriptionId}/enterprise_analytics?type=summary`, { starting_at, ending_at });
|
|
2002
2058
|
}
|