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:
parent
b32a20fb29
commit
a9f431a6a2
@ -85,6 +85,10 @@ class PaymentSchedule < PaymentDocument
|
|||||||
PaymentGatewayService.new.pay_subscription(self, gateway_method_id)
|
PaymentGatewayService.new.pay_subscription(self, gateway_method_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def post_save_extend(gateway_method_id)
|
||||||
|
PaymentGatewayService.new.extend_subscription(self, gateway_method_id)
|
||||||
|
end
|
||||||
|
|
||||||
def render_resource
|
def render_resource
|
||||||
{ partial: 'api/payment_schedules/payment_schedule', locals: { payment_schedule: self } }
|
{ partial: 'api/payment_schedules/payment_schedule', locals: { payment_schedule: self } }
|
||||||
end
|
end
|
||||||
|
@ -27,6 +27,10 @@ class PaymentGatewayService
|
|||||||
@gateway.pay_subscription(payment_schedule, gateway_object_id)
|
@gateway.pay_subscription(payment_schedule, gateway_object_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def extend_subscription(payment_schedule, gateway_object_id)
|
||||||
|
@gateway.extend_subscription(payment_schedule, gateway_object_id)
|
||||||
|
end
|
||||||
|
|
||||||
def create_user(user_id)
|
def create_user(user_id)
|
||||||
@gateway.create_user(user_id)
|
@gateway.create_user(user_id)
|
||||||
end
|
end
|
||||||
|
@ -54,7 +54,7 @@ class Subscriptions::Subscribe
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
payment.save
|
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
|
UsersCredits::Manager.new(user: new_sub.user).reset_credits
|
||||||
return new_sub
|
return new_sub
|
||||||
end
|
end
|
||||||
|
@ -48,6 +48,10 @@ class PayZen::Service < Payment::Service
|
|||||||
pgo_sub.save!
|
pgo_sub.save!
|
||||||
end
|
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)
|
def process_payment_schedule_item(payment_schedule_item)
|
||||||
pz_order = payment_schedule_item.payment_schedule.gateway_order.retrieve
|
pz_order = payment_schedule_item.payment_schedule.gateway_order.retrieve
|
||||||
transaction = pz_order['answer']['transactions'].last
|
transaction = pz_order['answer']['transactions'].last
|
||||||
|
@ -15,7 +15,7 @@ class Stripe::Item < Payment::Item
|
|||||||
end
|
end
|
||||||
|
|
||||||
def payment_mean?
|
def payment_mean?
|
||||||
klass == 'Stripe::SetupIntent'
|
klass == 'Stripe::PaymentMethod'
|
||||||
end
|
end
|
||||||
|
|
||||||
def subscription?
|
def subscription?
|
||||||
|
@ -14,8 +14,11 @@ class Stripe::Service < Payment::Service
|
|||||||
handle_wallet_transaction(payment_schedule)
|
handle_wallet_transaction(payment_schedule)
|
||||||
|
|
||||||
stp_subscription = Stripe::Subscription.retrieve(subscription_id, api_key: stripe_key)
|
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 = PaymentGatewayObject.new(item: payment_schedule)
|
||||||
pgo.gateway_object = stp_subscription
|
pgo.gateway_object = payment_method
|
||||||
pgo.save!
|
pgo.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -56,6 +59,16 @@ class Stripe::Service < Payment::Service
|
|||||||
}, { api_key: stripe_key })
|
}, { api_key: stripe_key })
|
||||||
end
|
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)
|
def create_user(user_id)
|
||||||
StripeWorker.perform_async(:create_stripe_customer, user_id)
|
StripeWorker.perform_async(:create_stripe_customer, user_id)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user