1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-29 18:52:22 +01:00

Merge branch 'extend_subscription' into dev

This commit is contained in:
Sylvain 2021-10-07 18:04:38 +02:00
commit 2b088ff035
6 changed files with 35 additions and 3 deletions

View File

@ -81,6 +81,10 @@ class PaymentSchedule < PaymentDocument
PaymentGatewayService.new.create_subscription(self, gateway_method_id)
end
def post_save_extend(gateway_method_id)
PaymentGatewayService.new.extend_subscription(self, gateway_method_id)
end
def render_resource
{ partial: 'api/payment_schedules/payment_schedule', locals: { payment_schedule: self } }
end

View File

@ -23,6 +23,10 @@ class PaymentGatewayService
@gateway.create_subscription(payment_schedule, gateway_object_id)
end
def extend_subscription(payment_schedule, gateway_object_id)
@gateway.extend_subscription(payment_schedule, gateway_object_id)
end
def create_user(user_id)
@gateway.create_user(user_id)
end

View File

@ -14,7 +14,7 @@ class Subscriptions::Subscribe
new_sub = Subscription.create(
plan_id: subscription.plan_id,
statistic_profile_id: subscription.statistic_profile_id,
statistic_profile_id: subscription.statistic_profile_id
)
new_sub.expiration_date = new_expiration_date
if new_sub.save
@ -54,7 +54,7 @@ class Subscriptions::Subscribe
)
end
payment.save
payment.post_save(schedule&.gateway_payment_mean&.id)
payment.post_save_extend(schedule&.gateway_payment_mean&.id)
UsersCredits::Manager.new(user: new_sub.user).reset_credits
return new_sub
end

View File

@ -48,6 +48,10 @@ class PayZen::Service < Payment::Service
pgo_sub.save!
end
def extend_subscription(payment_schedule, payment_method_id)
create_subscription(payment_schedule, payment_method_id)
end
def process_payment_schedule_item(payment_schedule_item)
pz_order = payment_schedule_item.payment_schedule.gateway_order.retrieve
transaction = pz_order['answer']['transactions'].last

View File

@ -15,7 +15,7 @@ class Stripe::Item < Payment::Item
end
def payment_mean?
klass == 'Stripe::SetupIntent'
klass == 'Stripe::PaymentMethod'
end
def subscription?

View File

@ -50,6 +50,26 @@ class Stripe::Service < Payment::Service
pgo = PaymentGatewayObject.new(item: payment_schedule)
pgo.gateway_object = stp_subscription
pgo.save!
payment_method_id = stp_subscription.default_payment_method
payment_method = Stripe::PaymentMethod.retrieve(payment_method_id, api_key: stripe_key)
pgo2 = PaymentGatewayObject.new(item: payment_schedule)
pgo2.gateway_object = payment_method
pgo2.save!
end
def extend_subscription(payment_schedule, payment_method_id)
# TODO, use Stripe::Subscription.update(sub_xxx, {cancel_at: new_date}, {api_key: stripe_key})
# FIXME, argument cart missing
stp_subscription = subscribe(payment_schedule, payment_method_id)
# not required?
handle_wallet_transaction(payment_schedule)
pgo = PaymentGatewayObject.new(item: payment_schedule)
pgo.gateway_object = stp_subscription
pgo.save!
end
def create_user(user_id)