stub stripe payment create

This commit is contained in:
Rimian Perkins 2019-09-11 19:55:35 +10:00
parent d71ab48fff
commit af97581911
3 changed files with 28 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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