stub stripe payment create
This commit is contained in:
parent
d71ab48fff
commit
af97581911
|
@ -2,13 +2,33 @@
|
||||||
|
|
||||||
module DiscoursePatrons
|
module DiscoursePatrons
|
||||||
class PatronsController < ApplicationController
|
class PatronsController < ApplicationController
|
||||||
|
skip_before_action :verify_authenticity_token, only: [:create]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
result = {}
|
result = {}
|
||||||
render json: result
|
render json: result
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
render json: {}
|
::Stripe.api_key = SiteSetting.discourse_patrons_secret_key
|
||||||
|
|
||||||
|
begin
|
||||||
|
|
||||||
|
response = ::Stripe::PaymentIntent.create(
|
||||||
|
amount: params[:amount],
|
||||||
|
currency: SiteSetting.discourse_patrons_currency,
|
||||||
|
payment_method_types: ['card'],
|
||||||
|
payment_method: params[:paymentMethodId],
|
||||||
|
confirm: true,
|
||||||
|
)
|
||||||
|
|
||||||
|
rescue ::Stripe::InvalidRequestError => e
|
||||||
|
response = { error: e }
|
||||||
|
rescue ::Stripe::CardError => e
|
||||||
|
response = { error: 'Card Declined' }
|
||||||
|
end
|
||||||
|
|
||||||
|
render json: response
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# frozen_string_literal: true.
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# name: Discourse Patrons
|
# name: Discourse Patrons
|
||||||
# about: Integrates Stripe into Discourse to allow visitors to make payments
|
# about: Integrates Stripe into Discourse to allow visitors to make payments
|
||||||
|
|
|
@ -14,7 +14,13 @@ module DiscoursePatrons
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'create' do
|
describe 'create' do
|
||||||
|
before do
|
||||||
|
SiteSetting.stubs(:discourse_patrons_currency).returns('AUD')
|
||||||
|
SiteSetting.stubs(:discourse_patrons_secret_key).returns('xyz-678')
|
||||||
|
end
|
||||||
|
|
||||||
it 'responds ok' do
|
it 'responds ok' do
|
||||||
|
::Stripe::PaymentIntent.expects(:create)
|
||||||
post :create, params: {}, format: :json
|
post :create, params: {}, format: :json
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue