normalize the message from stripe
This commit is contained in:
parent
d98ba20d0d
commit
e09b852361
|
@ -7,12 +7,11 @@ module DiscourseDonations
|
||||||
skip_before_filter :verify_authenticity_token, only: [:create]
|
skip_before_filter :verify_authenticity_token, only: [:create]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if !email.nil? || email.empty?
|
if email.present?
|
||||||
response = {}
|
|
||||||
else
|
|
||||||
byebug
|
|
||||||
payment = DiscourseDonations::Stripe.new(secret_key, stripe_options)
|
payment = DiscourseDonations::Stripe.new(secret_key, stripe_options)
|
||||||
response = payment.charge(email, params)
|
response = payment.charge(email, params)
|
||||||
|
else
|
||||||
|
response = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
render :json => response
|
render :json => response
|
||||||
|
|
|
@ -18,6 +18,7 @@ module DiscourseDonations
|
||||||
description: @description,
|
description: @description,
|
||||||
currency: @currency
|
currency: @currency
|
||||||
)
|
)
|
||||||
|
@charge[:message] = @charge[:outcome][:seller_message] if @charge[:outcome]
|
||||||
@charge
|
@charge
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ after_initialize do
|
||||||
header_script = '<script src="https://js.stripe.com/v3/"></script>'
|
header_script = '<script src="https://js.stripe.com/v3/"></script>'
|
||||||
discourse_donations_theme = Theme.find_or_create_by(name: 'Discourse Donations Header', hidden: false, user_id: -1)
|
discourse_donations_theme = Theme.find_or_create_by(name: 'Discourse Donations Header', hidden: false, user_id: -1)
|
||||||
discourse_donations_theme.set_field('common', 'head_tag', header_script)
|
discourse_donations_theme.set_field('common', 'head_tag', header_script)
|
||||||
discourse_donations_theme.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Discourse::Application.routes.prepend do
|
Discourse::Application.routes.prepend do
|
||||||
|
|
|
@ -20,16 +20,6 @@ module DiscourseDonations
|
||||||
email: email,
|
email: email,
|
||||||
source: 'stripe-token'
|
source: 'stripe-token'
|
||||||
).returns(customer)
|
).returns(customer)
|
||||||
::Stripe::Charge.expects(:create).with(
|
|
||||||
customer: customer.id,
|
|
||||||
amount: params[:amount],
|
|
||||||
description: stripe_options[:description],
|
|
||||||
currency: stripe_options[:currency]
|
|
||||||
)
|
|
||||||
subject.charge(email, params)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'has a message' do
|
|
||||||
::Stripe::Charge.expects(:create).with(
|
::Stripe::Charge.expects(:create).with(
|
||||||
customer: customer.id,
|
customer: customer.id,
|
||||||
amount: params[:amount],
|
amount: params[:amount],
|
||||||
|
@ -42,7 +32,13 @@ module DiscourseDonations
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
subject.charge(email, params)
|
subject.charge(email, params)
|
||||||
expect(subject.message).to eq 'yay!'
|
end
|
||||||
|
|
||||||
|
it 'has a message' do
|
||||||
|
::Stripe::Customer.expects(:create).returns(customer)
|
||||||
|
::Stripe::Charge.expects(:create).returns({ outcome: { seller_message: 'yay!' } })
|
||||||
|
response = subject.charge(email, params)
|
||||||
|
expect(response[:message]).to eq 'yay!'
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.successful?' do
|
describe '.successful?' do
|
||||||
|
|
Loading…
Reference in New Issue