FIX: Payments not showing up for users (#233)
Pricing table payments for one off purchases need to be attached to the customer or they don't show up on the user's billing payments page.
This commit is contained in:
parent
a2c70deeff
commit
700c5e7727
|
@ -57,9 +57,13 @@ module DiscourseSubscriptions
|
||||||
discourse_customer = Customer.create(user_id: user.id, customer_id: customer_id)
|
discourse_customer = Customer.create(user_id: user.id, customer_id: customer_id)
|
||||||
|
|
||||||
subscription = checkout_session[:subscription]
|
subscription = checkout_session[:subscription]
|
||||||
|
payment_intent_id = checkout_session[:payment_intent]
|
||||||
|
|
||||||
if !subscription.nil?
|
if subscription.present?
|
||||||
Subscription.create(customer_id: discourse_customer.id, external_id: subscription)
|
Subscription.create(customer_id: discourse_customer.id, external_id: subscription)
|
||||||
|
elsif payment_intent_id
|
||||||
|
# Attach the payment intent to the customer for one-off purchases
|
||||||
|
::Stripe::PaymentIntent.update(payment_intent_id, { customer: customer_id })
|
||||||
end
|
end
|
||||||
|
|
||||||
line_items =
|
line_items =
|
||||||
|
|
|
@ -28,10 +28,18 @@ module DiscourseSubscriptions
|
||||||
payments_from_invoices =
|
payments_from_invoices =
|
||||||
payments[:data].select { |payment| invoice_ids.include?(payment[:invoice]) }
|
payments[:data].select { |payment| invoice_ids.include?(payment[:invoice]) }
|
||||||
|
|
||||||
|
if SiteSetting.discourse_subscriptions_enable_verbose_logging
|
||||||
|
Rails.logger.warn("Payments from invoices: #{payments_from_invoices}")
|
||||||
|
end
|
||||||
|
|
||||||
# Pricing table one-off purchases do not have invoices
|
# Pricing table one-off purchases do not have invoices
|
||||||
payments_without_invoices =
|
payments_without_invoices =
|
||||||
payments[:data].select { |payment| payment[:invoice].nil? }
|
payments[:data].select { |payment| payment[:invoice].nil? }
|
||||||
|
|
||||||
|
if SiteSetting.discourse_subscriptions_enable_verbose_logging
|
||||||
|
Rails.logger.warn("Payments without invoices: #{payments_without_invoices}")
|
||||||
|
end
|
||||||
|
|
||||||
data = data | payments_from_invoices | payments_without_invoices
|
data = data | payments_from_invoices | payments_without_invoices
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -94,6 +94,7 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
||||||
metadata: {
|
metadata: {
|
||||||
},
|
},
|
||||||
mode: "subscription",
|
mode: "subscription",
|
||||||
|
payment_intent: "pi_3PsohkGHcn",
|
||||||
payment_status: "paid",
|
payment_status: "paid",
|
||||||
status: "complete",
|
status: "complete",
|
||||||
submit_type: nil,
|
submit_type: nil,
|
||||||
|
@ -219,6 +220,11 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
||||||
|
|
||||||
::Stripe::Webhook.stubs(:construct_event).returns(event)
|
::Stripe::Webhook.stubs(:construct_event).returns(event)
|
||||||
::Stripe::Customer.stubs(:create).returns(id: "cus_1234")
|
::Stripe::Customer.stubs(:create).returns(id: "cus_1234")
|
||||||
|
|
||||||
|
::Stripe::PaymentIntent
|
||||||
|
.expects(:update)
|
||||||
|
.with("pi_3PsohkGHcn", { customer: "cus_1234" })
|
||||||
|
.returns({ id: "pi_3PsohkGHcn" })
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is returns 200" do
|
it "is returns 200" do
|
||||||
|
|
Loading…
Reference in New Issue