@posiwise/common-services 0.2.23 → 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.
|
@@ -803,6 +803,7 @@ class UserService {
|
|
|
803
803
|
this.toast = toast;
|
|
804
804
|
this.endpoint = USER_PATH;
|
|
805
805
|
this.isTosModalOpen = false;
|
|
806
|
+
this.isSecondaryPaymentModalOpen = false;
|
|
806
807
|
}
|
|
807
808
|
getUserState() {
|
|
808
809
|
return this.store.select(getUser);
|
|
@@ -814,8 +815,51 @@ class UserService {
|
|
|
814
815
|
this.router.navigate(['settings/security']);
|
|
815
816
|
}
|
|
816
817
|
this.checkAndHandleTosAcceptance(data);
|
|
818
|
+
this.checkAndHandleSecondaryPayment(data);
|
|
817
819
|
}));
|
|
818
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
|
+
}
|
|
819
863
|
/**
|
|
820
864
|
* Ensure the current user has accepted the latest Terms of Service for this domain.
|
|
821
865
|
* If the domain has a newer TOS version than the user's accepted timestamp, a blocking
|
|
@@ -1998,6 +2042,17 @@ class SubscriptionService {
|
|
|
1998
2042
|
updateCardDetails(data, subscription_id) {
|
|
1999
2043
|
return this.api.post(`/subscriptions/${subscription_id}/update_card`, data);
|
|
2000
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
|
+
}
|
|
2001
2056
|
getEnterpriseInsight(subscriptionId, starting_at, ending_at) {
|
|
2002
2057
|
return this.api.getWithParams(`/subscriptions/${subscriptionId}/enterprise_analytics?type=summary`, { starting_at, ending_at });
|
|
2003
2058
|
}
|