diff --git a/CHANGELOG.md b/CHANGELOG.md index 18aff1040..689622c9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Ability to create slots in the past - Ability to disable public account creation - Ability to select "bank transfer" as the payment mean for a payment schedule +- When a payment schedule was canceled by the payment gateway, inform the user in the interface - Updated caniuse db - Optimized the load time of the payment schedules list - Fix a bug: do not load Stripe if no keys were defined diff --git a/app/frontend/src/javascript/components/payment-schedule/payment-schedules-table.tsx b/app/frontend/src/javascript/components/payment-schedule/payment-schedules-table.tsx index b767d2bce..913fd9bc0 100644 --- a/app/frontend/src/javascript/components/payment-schedule/payment-schedules-table.tsx +++ b/app/frontend/src/javascript/components/payment-schedule/payment-schedules-table.tsx @@ -189,7 +189,9 @@ const PaymentSchedulesTableComponent: React.FC = ({ {t('app.shared.schedules_table.update_card')} ); + case PaymentScheduleItemState.GatewayCanceled: case PaymentScheduleItemState.Error: + // if the payment schedule was canceled by the gateway, or // if the payment is in error, the schedule is over, and we can't update the card cardUpdateButton.set(schedule.id, true); if (!isPrivileged()) { diff --git a/app/frontend/src/javascript/models/payment-schedule.ts b/app/frontend/src/javascript/models/payment-schedule.ts index 3a637ecc6..625ae2081 100644 --- a/app/frontend/src/javascript/models/payment-schedule.ts +++ b/app/frontend/src/javascript/models/payment-schedule.ts @@ -4,7 +4,8 @@ export enum PaymentScheduleItemState { RequirePaymentMethod = 'requires_payment_method', RequireAction = 'requires_action', Paid = 'paid', - Error = 'error' + Error = 'error', + GatewayCanceled = 'gateway_canceled' } export enum PaymentMethod { diff --git a/config/locales/app.shared.en.yml b/config/locales/app.shared.en.yml index 2cadef5ad..63c96c2a2 100644 --- a/config/locales/app.shared.en.yml +++ b/config/locales/app.shared.en.yml @@ -493,6 +493,7 @@ en: state_requires_action: "Action required" state_paid: "Paid" state_error: "Error" + state_gateway_canceled: "Canceled by the payment gateway" state_canceled: "Canceled" method_card: "by card" method_check: "by check" diff --git a/lib/pay_zen/service.rb b/lib/pay_zen/service.rb index 3cdfa1af2..a3f1c1cc3 100644 --- a/lib/pay_zen/service.rb +++ b/lib/pay_zen/service.rb @@ -78,6 +78,12 @@ class PayZen::Service < Payment::Service end def process_payment_schedule_item(payment_schedule_item) + pz_subscription = payment_schedule_item.gateway_subscription.retrieve + if DateTime.parse(pz_subscription['answer']['cancelDate']) < DateTime.current + # the subscription was canceled by the gateway => update the status + payment_schedule_item.update_attributes(state: 'gateway_canceled') + return + end pz_order = payment_schedule_item.payment_schedule.gateway_order.retrieve transaction = pz_order['answer']['transactions'].last return unless transaction_matches?(transaction, payment_schedule_item) diff --git a/lib/stripe/service.rb b/lib/stripe/service.rb index 84933312b..15544828c 100644 --- a/lib/stripe/service.rb +++ b/lib/stripe/service.rb @@ -94,6 +94,11 @@ class Stripe::Service < Payment::Service def process_payment_schedule_item(payment_schedule_item) stripe_key = Setting.get('stripe_secret_key') stp_subscription = payment_schedule_item.payment_schedule.gateway_subscription.retrieve + if stp_subscription.status == 'canceled' + # the subscription was canceled by the gateway => update the status + payment_schedule_item.update_attributes(state: 'gateway_canceled') + return + end stp_invoice = Stripe::Invoice.retrieve(stp_subscription.latest_invoice, api_key: stripe_key) if stp_invoice.status == 'paid' ##### Successfully paid