mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-04-12 02:02:31 +02:00
fix stripe subscription w/ coupon + wallet
This commit is contained in:
parent
b8319a5124
commit
dc00df4afc
@ -47,15 +47,18 @@ Application.Directives.directive('coupon', [ '$rootScope', 'Coupon', '_t', funct
|
|||||||
$scope.messages = [];
|
$scope.messages = [];
|
||||||
if ($scope.couponCode === '') {
|
if ($scope.couponCode === '') {
|
||||||
$scope.status = 'pending';
|
$scope.status = 'pending';
|
||||||
return $scope.coupon = null;
|
$scope.coupon = null;
|
||||||
} else {
|
} else {
|
||||||
return Coupon.validate({ code: $scope.couponCode, user_id: $scope.userId, amount: $scope.total }, function (res) {
|
Coupon.validate({ code: $scope.couponCode, user_id: $scope.userId, amount: $scope.total }, function (res) {
|
||||||
$scope.status = 'valid';
|
$scope.status = 'valid';
|
||||||
$scope.coupon = res;
|
$scope.coupon = res;
|
||||||
if (res.type === 'percent_off') {
|
if (res.type === 'percent_off') {
|
||||||
return $scope.messages.push({ type: 'success', message: _t('app.shared.coupon_input.the_coupon_has_been_applied_you_get_PERCENT_discount', { PERCENT: res.percent_off }) });
|
$scope.messages.push({ type: 'success', message: _t('app.shared.coupon_input.the_coupon_has_been_applied_you_get_PERCENT_discount', { PERCENT: res.percent_off }) });
|
||||||
} else {
|
} else {
|
||||||
return $scope.messages.push({ type: 'success', message: _t('app.shared.coupon_input.the_coupon_has_been_applied_you_get_AMOUNT_CURRENCY', { AMOUNT: res.amount_off, CURRENCY: $rootScope.currencySymbol }) });
|
$scope.messages.push({ type: 'success', message: _t('app.shared.coupon_input.the_coupon_has_been_applied_you_get_AMOUNT_CURRENCY', { AMOUNT: res.amount_off, CURRENCY: $rootScope.currencySymbol }) });
|
||||||
|
}
|
||||||
|
if (res.validity_per_user === 'once') {
|
||||||
|
$scope.messages.push({ type: 'warning', message: _t('app.shared.coupon_input.coupon_validity_once') });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
, function (err) {
|
, function (err) {
|
||||||
|
@ -145,15 +145,13 @@ class Price < ApplicationRecord
|
|||||||
total_amount = cs.apply(total_amount, cp)
|
total_amount = cs.apply(total_amount, cp)
|
||||||
|
|
||||||
# == generate PaymentSchedule (if applicable) ===
|
# == generate PaymentSchedule (if applicable) ===
|
||||||
schedule = if options[:payment_schedule] && plan.monthly_payment
|
schedule = if options[:payment_schedule] && plan&.monthly_payment
|
||||||
PaymentScheduleService.new.compute(plan, _amount_no_coupon, cp)
|
PaymentScheduleService.new.compute(plan, _amount_no_coupon, cp)
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
if schedule
|
|
||||||
total_amount -= schedule[:payment_schedule].total
|
total_amount = schedule[:items][0].amount if schedule
|
||||||
total_amount += schedule[:items][0].amount
|
|
||||||
end
|
|
||||||
|
|
||||||
# return result
|
# return result
|
||||||
{
|
{
|
||||||
|
@ -10,13 +10,8 @@ class PaymentScheduleService
|
|||||||
##
|
##
|
||||||
def compute(plan, total, coupon = nil)
|
def compute(plan, total, coupon = nil)
|
||||||
other_items = total - plan.amount
|
other_items = total - plan.amount
|
||||||
price = if coupon
|
# base monthly price of the plan
|
||||||
cs = CouponService.new
|
price = plan.amount
|
||||||
other_items = cs.ventilate(total, other_items, coupon)
|
|
||||||
cs.ventilate(total, plan.amount, coupon)
|
|
||||||
else
|
|
||||||
plan.amount
|
|
||||||
end
|
|
||||||
ps = PaymentSchedule.new(scheduled: plan, total: price + other_items, coupon: coupon)
|
ps = PaymentSchedule.new(scheduled: plan, total: price + other_items, coupon: coupon)
|
||||||
deadlines = plan.duration / 1.month
|
deadlines = plan.duration / 1.month
|
||||||
per_month = (price / deadlines).truncate
|
per_month = (price / deadlines).truncate
|
||||||
@ -36,6 +31,13 @@ class PaymentScheduleService
|
|||||||
else
|
else
|
||||||
per_month
|
per_month
|
||||||
end
|
end
|
||||||
|
if coupon
|
||||||
|
cs = CouponService.new
|
||||||
|
if (coupon.validity_per_user == 'once' && i.zero?) || coupon.validity_per_user == 'forever'
|
||||||
|
details[:without_coupon] = amount
|
||||||
|
amount = cs.apply(amount, coupon)
|
||||||
|
end
|
||||||
|
end
|
||||||
items.push PaymentScheduleItem.new(
|
items.push PaymentScheduleItem.new(
|
||||||
amount: amount,
|
amount: amount,
|
||||||
due_date: date,
|
due_date: date,
|
||||||
|
@ -80,7 +80,11 @@ class WalletService
|
|||||||
# @param coupon {Coupon|String} Coupon object or code
|
# @param coupon {Coupon|String} Coupon object or code
|
||||||
##
|
##
|
||||||
def self.wallet_amount_debit(payment, user, coupon = nil)
|
def self.wallet_amount_debit(payment, user, coupon = nil)
|
||||||
total = payment.total
|
total = if payment.class == PaymentSchedule
|
||||||
|
payment.payment_schedule_items.first.amount
|
||||||
|
else
|
||||||
|
payment.total
|
||||||
|
end
|
||||||
total = CouponService.new.apply(total, coupon, user.id) if coupon
|
total = CouponService.new.apply(total, coupon, user.id) if coupon
|
||||||
|
|
||||||
wallet_amount = (user.wallet.amount * 100).to_i
|
wallet_amount = (user.wallet.amount * 100).to_i
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
json.extract! @coupon, :id, :code, :type, :percent_off
|
# frozen_string_literal: true
|
||||||
json.amount_off (@coupon.amount_off / 100.00) unless @coupon.amount_off.nil?
|
|
||||||
|
json.extract! @coupon, :id, :code, :type, :percent_off, :validity_per_user
|
||||||
|
json.amount_off (@coupon.amount_off / 100.00) unless @coupon.amount_off.nil?
|
||||||
|
@ -371,6 +371,7 @@ en:
|
|||||||
code_: "Code:"
|
code_: "Code:"
|
||||||
the_coupon_has_been_applied_you_get_PERCENT_discount: "The coupon has been applied. You get a {PERCENT}% discount."
|
the_coupon_has_been_applied_you_get_PERCENT_discount: "The coupon has been applied. You get a {PERCENT}% discount."
|
||||||
the_coupon_has_been_applied_you_get_AMOUNT_CURRENCY: "The coupon has been applied. You get a discount of {AMOUNT} {CURRENCY}."
|
the_coupon_has_been_applied_you_get_AMOUNT_CURRENCY: "The coupon has been applied. You get a discount of {AMOUNT} {CURRENCY}."
|
||||||
|
coupon_validity_once: "This coupon is valid only once. In case of payment schedule, only for the first deadline."
|
||||||
unable_to_apply_the_coupon_because_disabled: "Unable to apply the coupon: this code was disabled."
|
unable_to_apply_the_coupon_because_disabled: "Unable to apply the coupon: this code was disabled."
|
||||||
unable_to_apply_the_coupon_because_expired: "Unable to apply the coupon: this code has expired."
|
unable_to_apply_the_coupon_because_expired: "Unable to apply the coupon: this code has expired."
|
||||||
unable_to_apply_the_coupon_because_sold_out: "Unable to apply the coupon: this code reached its quota."
|
unable_to_apply_the_coupon_because_sold_out: "Unable to apply the coupon: this code reached its quota."
|
||||||
|
@ -371,6 +371,7 @@ fr:
|
|||||||
code_: "Code :"
|
code_: "Code :"
|
||||||
the_coupon_has_been_applied_you_get_PERCENT_discount: "Le code promo a bien été appliqué. Vous bénéficiez d'une remise de {PERCENT} %."
|
the_coupon_has_been_applied_you_get_PERCENT_discount: "Le code promo a bien été appliqué. Vous bénéficiez d'une remise de {PERCENT} %."
|
||||||
the_coupon_has_been_applied_you_get_AMOUNT_CURRENCY: "Le code promo a bien été appliqué. Vous bénéficiez d'une remise de {AMOUNT} {CURRENCY}."
|
the_coupon_has_been_applied_you_get_AMOUNT_CURRENCY: "Le code promo a bien été appliqué. Vous bénéficiez d'une remise de {AMOUNT} {CURRENCY}."
|
||||||
|
coupon_validity_once: "Ce code promo n'est valide qu'une seule fois. En cas de paiement échelonné, seulement pour la première échéance."
|
||||||
unable_to_apply_the_coupon_because_disabled: "Impossible d'appliquer la réduction : ce code promo a été désactivé."
|
unable_to_apply_the_coupon_because_disabled: "Impossible d'appliquer la réduction : ce code promo a été désactivé."
|
||||||
unable_to_apply_the_coupon_because_expired: "Impossible d'appliquer la réduction : ce code promo a expiré."
|
unable_to_apply_the_coupon_because_expired: "Impossible d'appliquer la réduction : ce code promo a expiré."
|
||||||
unable_to_apply_the_coupon_because_sold_out: "Impossible d'appliquer la réduction : ce code promo a atteint son quota."
|
unable_to_apply_the_coupon_because_sold_out: "Impossible d'appliquer la réduction : ce code promo a atteint son quota."
|
||||||
|
@ -181,7 +181,7 @@ You can subscribe to [this atom feed](https://github.com/sleede/fab-manager/rele
|
|||||||
|
|
||||||
4. remove old assets
|
4. remove old assets
|
||||||
|
|
||||||
`rm -Rf public/assets/`
|
`rm -Rf public/packs/`
|
||||||
|
|
||||||
5. compile new assets
|
5. compile new assets
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user