mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-11 05:54:15 +01:00
Merge branch 'extend_subscription' into dev
This commit is contained in:
commit
2b088ff035
@ -81,6 +81,10 @@ class PaymentSchedule < PaymentDocument
|
|||||||
PaymentGatewayService.new.create_subscription(self, gateway_method_id)
|
PaymentGatewayService.new.create_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
|
||||||
|
@ -23,6 +23,10 @@ class PaymentGatewayService
|
|||||||
@gateway.create_subscription(payment_schedule, gateway_object_id)
|
@gateway.create_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
|
||||||
|
@ -14,7 +14,7 @@ class Subscriptions::Subscribe
|
|||||||
|
|
||||||
new_sub = Subscription.create(
|
new_sub = Subscription.create(
|
||||||
plan_id: subscription.plan_id,
|
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
|
new_sub.expiration_date = new_expiration_date
|
||||||
if new_sub.save
|
if new_sub.save
|
||||||
@ -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?
|
||||||
|
@ -50,6 +50,26 @@ class Stripe::Service < Payment::Service
|
|||||||
pgo = PaymentGatewayObject.new(item: payment_schedule)
|
pgo = PaymentGatewayObject.new(item: payment_schedule)
|
||||||
pgo.gateway_object = stp_subscription
|
pgo.gateway_object = stp_subscription
|
||||||
pgo.save!
|
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
|
end
|
||||||
|
|
||||||
def create_user(user_id)
|
def create_user(user_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user