1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00

fix test on paymentSchedules

This commit is contained in:
Sylvain 2021-10-15 11:55:30 +02:00
parent 315e899540
commit 3349cc3a2d
6 changed files with 2083 additions and 2032 deletions

View File

@ -97,7 +97,7 @@ class API::StripeController < API::PaymentsController
cart = shopping_cart cart = shopping_cart
if subscription&.status == 'active' if subscription&.status == 'active'
res = on_payment_success(subscription.latest_invoice.payment_intent, cart) res = on_payment_success(subscription, cart)
render generate_payment_response(subscription.latest_invoice.payment_intent, 'subscription', res) render generate_payment_response(subscription.latest_invoice.payment_intent, 'subscription', res)
else else
render generate_payment_response(subscription.latest_invoice.payment_intent, 'subscription', nil, subscription.id) render generate_payment_response(subscription.latest_invoice.payment_intent, 'subscription', nil, subscription.id)

View File

@ -130,7 +130,7 @@ class Invoice < PaymentDocument
return true if user.nil? return true if user.nil?
# workaround for reservation saved after invoice # workaround for reservation saved after invoice
if main_item.object_type == 'Reservation' && main_item.object&.reservable_type == 'Training' if main_item&.object_type == 'Reservation' && main_item&.object&.reservable_type == 'Training'
user.trainings.include?(main_item.object.reservable_id) user.trainings.include?(main_item.object.reservable_id)
else else
false false

View File

@ -50,20 +50,16 @@ class Stripe::Service < Payment::Service
stp_subscription stp_subscription
end end
def create_subscription(payment_schedule, payment_intent_id) def create_subscription(payment_schedule, stp_subscription_id)
stripe_key = Setting.get('stripe_secret_key') stripe_key = Setting.get('stripe_secret_key')
pi = Stripe::PaymentIntent.retrieve({ id: payment_intent_id, expand: %w[invoice] }, { api_key: stripe_key }) stp_subscription = Stripe::Subscription.retrieve({ id: stp_subscription_id }, { api_key: stripe_key })
stp_subscription = Stripe::Subscription.retrieve(pi.invoice.subscription, api_key: stripe_key)
pgo = PaymentGatewayObject.new(item: payment_schedule)
pgo.gateway_object = stp_subscription
pgo.save!
payment_method_id = stp_subscription.default_payment_method payment_method_id = stp_subscription.default_payment_method
payment_method = Stripe::PaymentMethod.retrieve(payment_method_id, api_key: stripe_key) payment_method = Stripe::PaymentMethod.retrieve(payment_method_id, api_key: stripe_key)
pgo2 = PaymentGatewayObject.new(item: payment_schedule) pgo = PaymentGatewayObject.new(item: payment_schedule)
pgo2.gateway_object = payment_method pgo.gateway_object = payment_method
pgo2.save! pgo.save!
end end
def extend_subscription(payment_schedule, payment_method_id) def extend_subscription(payment_schedule, payment_method_id)

View File

@ -818,7 +818,8 @@ class Reservations::CreateTest < ActionDispatch::IntegrationTest
} }
], ],
payment_schedule: true, payment_schedule: true,
payment_method: 'cart' payment_method: 'card',
coupon_code: 'GIME3EUR'
} }
}.to_json, headers: default_headers }.to_json, headers: default_headers
@ -831,9 +832,6 @@ class Reservations::CreateTest < ActionDispatch::IntegrationTest
assert_not_nil res[:id] assert_not_nil res[:id]
end end
# Check response format & status
assert_equal 201, response.status, response.body
assert_equal Mime[:json], response.content_type
assert_equal reservations_count + 1, Reservation.count, 'missing the reservation' assert_equal reservations_count + 1, Reservation.count, 'missing the reservation'
assert_equal invoice_count, Invoice.count, "an invoice was generated but it shouldn't" assert_equal invoice_count, Invoice.count, "an invoice was generated but it shouldn't"
assert_equal invoice_items_count, InvoiceItem.count, "some invoice items were generated but they shouldn't" assert_equal invoice_items_count, InvoiceItem.count, "some invoice items were generated but they shouldn't"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long