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
|
||||
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
|
||||
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)
|
||||
|
||||
render json: { status: stp_invoice.status, error: e }, status: :unprocessable_entity
|
||||
res = PaymentGatewayService.new.pay_payment_schedule_item(@payment_schedule_item)
|
||||
if res.error
|
||||
render json: res, status: :unprocessable_entity
|
||||
else
|
||||
render json: res, status: :ok
|
||||
end
|
||||
end
|
||||
|
||||
def cancel
|
||||
|
@ -36,6 +36,18 @@ class PaymentGatewayService
|
||||
end
|
||||
|
||||
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
|
||||
when /^PayZen::/
|
||||
require 'pay_zen/service'
|
||||
@ -47,7 +59,6 @@ class PaymentGatewayService
|
||||
require 'payment/service'
|
||||
Payment::Service
|
||||
end
|
||||
gateway = service.new
|
||||
gateway.process_payment_schedule_item(payment_schedule_item)
|
||||
service.new
|
||||
end
|
||||
end
|
||||
|
@ -15,4 +15,6 @@ class Payment::Service
|
||||
def create_or_update_product(_klass, _id); end
|
||||
|
||||
def process_payment_schedule_item(_payment_schedule_item); end
|
||||
|
||||
def pay_payment_schedule_item(_payment_schedule_item); end
|
||||
end
|
||||
|
@ -120,6 +120,20 @@ class Stripe::Service < Payment::Service
|
||||
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
|
||||
|
||||
def subscription_invoice_items(payment_schedule, subscription, first_item, reservable_stp_id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user