mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-18 07:52:23 +01:00
WIP: pay item
This commit is contained in:
parent
430db7777f
commit
89adcf1a9d
@ -53,18 +53,13 @@ class API::PaymentSchedulesController < API::ApiController
|
|||||||
|
|
||||||
def pay_item
|
def pay_item
|
||||||
authorize @payment_schedule_item.payment_schedule
|
authorize @payment_schedule_item.payment_schedule
|
||||||
# FIXME
|
|
||||||
stripe_key = Setting.get('stripe_secret_key')
|
|
||||||
stp_invoice = Stripe::Invoice.pay(@payment_schedule_item.payment_gateway_object.gateway_object_id, {}, { api_key: stripe_key })
|
|
||||||
PaymentScheduleItemWorker.new.perform(@payment_schedule_item.id)
|
|
||||||
|
|
||||||
render json: { status: stp_invoice.status }, status: :ok
|
res = PaymentGatewayService.new.pay_payment_schedule_item(@payment_schedule_item)
|
||||||
rescue Stripe::StripeError => e
|
if res.error
|
||||||
stripe_key = Setting.get('stripe_secret_key')
|
render json: res, status: :unprocessable_entity
|
||||||
stp_invoice = Stripe::Invoice.retrieve(@payment_schedule_item.payment_gateway_object.gateway_object_id, api_key: stripe_key)
|
else
|
||||||
PaymentScheduleItemWorker.new.perform(@payment_schedule_item.id)
|
render json: res, status: :ok
|
||||||
|
end
|
||||||
render json: { status: stp_invoice.status, error: e }, status: :unprocessable_entity
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def cancel
|
def cancel
|
||||||
|
@ -36,6 +36,18 @@ class PaymentGatewayService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def process_payment_schedule_item(payment_schedule_item)
|
def process_payment_schedule_item(payment_schedule_item)
|
||||||
|
gateway = service_for_payment_schedule(payment_schedule_item.payment_schedule)
|
||||||
|
gateway.process_payment_schedule_item(payment_schedule_item)
|
||||||
|
end
|
||||||
|
|
||||||
|
def pay_payment_schedule_item(payment_schedule_item)
|
||||||
|
gateway = service_for_payment_schedule(payment_schedule_item.payment_schedule)
|
||||||
|
gateway.pay_payment_schedule_item(payment_schedule_item)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def service_for_payment_schedule(payment_schedule)
|
||||||
service = case payment_schedule_item.payment_schedule.gateway_subscription.klass
|
service = case payment_schedule_item.payment_schedule.gateway_subscription.klass
|
||||||
when /^PayZen::/
|
when /^PayZen::/
|
||||||
require 'pay_zen/service'
|
require 'pay_zen/service'
|
||||||
@ -47,7 +59,6 @@ class PaymentGatewayService
|
|||||||
require 'payment/service'
|
require 'payment/service'
|
||||||
Payment::Service
|
Payment::Service
|
||||||
end
|
end
|
||||||
gateway = service.new
|
service.new
|
||||||
gateway.process_payment_schedule_item(payment_schedule_item)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,4 +15,6 @@ class Payment::Service
|
|||||||
def create_or_update_product(_klass, _id); end
|
def create_or_update_product(_klass, _id); end
|
||||||
|
|
||||||
def process_payment_schedule_item(_payment_schedule_item); end
|
def process_payment_schedule_item(_payment_schedule_item); end
|
||||||
|
|
||||||
|
def pay_payment_schedule_item(_payment_schedule_item); end
|
||||||
end
|
end
|
||||||
|
@ -120,6 +120,20 @@ class Stripe::Service < Payment::Service
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pay_payment_schedule_item(payment_schedule_item)
|
||||||
|
stripe_key = Setting.get('stripe_secret_key')
|
||||||
|
stp_invoice = Stripe::Invoice.pay(@payment_schedule_item.payment_gateway_object.gateway_object_id, {}, { api_key: stripe_key })
|
||||||
|
PaymentScheduleItemWorker.new.perform(@payment_schedule_item.id)
|
||||||
|
|
||||||
|
{ status: stp_invoice.status }
|
||||||
|
rescue Stripe::StripeError => e
|
||||||
|
stripe_key = Setting.get('stripe_secret_key')
|
||||||
|
stp_invoice = Stripe::Invoice.retrieve(@payment_schedule_item.payment_gateway_object.gateway_object_id, api_key: stripe_key)
|
||||||
|
PaymentScheduleItemWorker.new.perform(@payment_schedule_item.id)
|
||||||
|
|
||||||
|
{ status: stp_invoice.status, error: e }
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def subscription_invoice_items(payment_schedule, subscription, first_item, reservable_stp_id)
|
def subscription_invoice_items(payment_schedule, subscription, first_item, reservable_stp_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user