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

fix bug: offer and extends subscription

This commit is contained in:
Du Peng 2021-09-30 14:46:47 +02:00 committed by Sylvain
parent b32a20fb29
commit a9f431a6a2
6 changed files with 28 additions and 3 deletions

View File

@ -85,6 +85,10 @@ class PaymentSchedule < PaymentDocument
PaymentGatewayService.new.pay_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

@ -27,6 +27,10 @@ class PaymentGatewayService
@gateway.pay_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

@ -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

@ -14,8 +14,11 @@ class Stripe::Service < Payment::Service
handle_wallet_transaction(payment_schedule)
stp_subscription = Stripe::Subscription.retrieve(subscription_id, api_key: stripe_key)
payment_method_id = stp_subscription.default_payment_method
payment_method = Stripe::PaymentMethod.retrieve(payment_method_id, api_key: stripe_key)
pgo = PaymentGatewayObject.new(item: payment_schedule)
pgo.gateway_object = stp_subscription
pgo.gateway_object = payment_method
pgo.save!
end
@ -56,6 +59,16 @@ class Stripe::Service < Payment::Service
}, { api_key: stripe_key })
end
def extend_subscription(payment_schedule, payment_method_id)
stp_subscription = pay_subscription(payment_schedule, payment_method_id)
handle_wallet_transaction(payment_schedule)
pgo = PaymentGatewayObject.new(item: payment_schedule)
pgo.gateway_object = stp_subscription
pgo.save!
end
def create_user(user_id)
StripeWorker.perform_async(:create_stripe_customer, user_id)
end