1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

[ongoing] upgrade stripe gem & api version to allow SCA

This commit is contained in:
Sylvain 2019-09-05 11:03:22 +02:00
parent 967f539ad9
commit a0961314a4
4 changed files with 38 additions and 12 deletions

View File

@ -103,7 +103,7 @@ gem 'sinatra', require: false
# Recurring jobs for Sidekiq
gem 'sidekiq-cron'
gem 'stripe', '1.30.2'
gem 'stripe', '5.1.1'
gem 'recurrence'

View File

@ -246,7 +246,6 @@ GEM
multi_xml (0.5.5)
multipart-post (2.0.0)
naught (1.1.0)
netrc (0.10.3)
nokogiri (1.10.1)
mini_portile2 (~> 2.4.0)
notify_with (0.0.2)
@ -345,10 +344,6 @@ GEM
ref (2.0.0)
responders (2.1.0)
railties (>= 4.2.0, < 5)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rolify (4.0.0)
rubocop (0.61.1)
jaro_winkler (~> 1.5.1)
@ -411,9 +406,7 @@ GEM
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.13)
stripe (1.30.2)
json (~> 1.8.1)
rest-client (~> 1.4)
stripe (5.1.1)
sys-filesystem (1.2.0)
ffi
term-ansicolor (1.3.2)
@ -546,7 +539,7 @@ DEPENDENCIES
sidekiq-cron
sinatra
spring
stripe (= 1.30.2)
stripe (= 5.1.1)
sys-filesystem
test_after_commit
therubyracer (= 0.12.0)

View File

@ -0,0 +1,31 @@
# frozen_string_literal: true
# API Controller for handling payments process in the front-end
class API::PaymentsController < API::ApiController
before_action :authenticate_user!
# TODO https://stripe.com/docs/payments/payment-intents/web-manual
def confirm_payment
data = JSON.parse(request.body.read.to_s)
begin
if data['payment_method_id']
# Create the PaymentIntent
intent = Stripe::PaymentIntent.create(
payment_method: data['payment_method_id'],
amount: 1099,
currency: 'usd',
confirmation_method: 'manual',
confirm: true
)
elsif data['payment_intent_id']
intent = Stripe::PaymentIntent.confirm(data['payment_intent_id'])
end
rescue Stripe::CardError => e
# Display error on client
return [200, { error: e.message }.to_json]
end
return generate_payment_response(intent)
end
end

View File

@ -1,4 +1,6 @@
require "stripe"
# frozen_string_literal: true
require 'stripe'
Stripe.api_key = Rails.application.secrets.stripe_api_key
Stripe.api_version = "2015-10-16"
Stripe.api_version = '2019-08-14'