This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/api/v1/credit_cards_controller.rb | |
module Api | |
module V1 | |
class CreditCardsController < Api::V1::ApiController | |
helper_method :shop | |
def index | |
service = StripeService.new(shop) | |
@card = service.credit_card_info | |
@customer = service.customer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/services/stripe_service.rb | |
require 'stripe' | |
class StripeService | |
class StripeException < StandardError | |
end | |
attr_reader :shop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
CardNumberElement, | |
CardExpiryElement, | |
CardCVCElement, | |
injectStripe | |
} from 'react-stripe-elements'; | |
import uuid from 'uuid/v1'; | |
/* Your other imports for a usual form */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Elements, StripeProvider } from 'react-stripe-elements'; | |
const withStripe = (WrappedComponent) => { | |
const Stripe = props => ( | |
<StripeProvider apiKey={process.env.stripe_key}> | |
<Elements | |
fonts={[{ | |
cssSrc: 'https://fonts.googleapis.com/css?family=Roboto:300,300i,400,500,600' | |
}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/intializers/stripe.rb | |
Rails.configuration.stripe = { | |
publishable_key: ENV['STRIPE_PUBLISHABLE_KEY'], | |
secret_key: ENV['STRIPE_SECRET_KEY'] | |
} | |
Stripe.api_key = Rails.configuration.stripe[:secret_key] |
NewerOlder