Pay comes with a lot of configuration out of the box for you, but you'll need to add your API tokens for your payment provider.
Pay automatically looks up credentials for each payment provider. We recommend storing them in the Rails credentials.
You'll need to add your API keys to your Rails credentials. You can do this by running:
rails credentials:edit --environment=development
They should be formatted like the following:
stripe:
private_key: xxxx
public_key: yyyy
signing_secret:
- aaaa
- bbbb
braintree:
private_key: xxxx
public_key: yyyy
merchant_id: aaaa
environment: sandbox
paddle:
vendor_id: xxxx
vendor_auth_code: yyyy
public_key_base64: MII...==
environment: sandbox
You can also nest these credentials under the Rails environment if using a shared credentials file or secrets.
development:
stripe:
private_key: xxxx
# ...
Pay will also check environment variables for API keys:
STRIPE_PUBLIC_KEY
STRIPE_PRIVATE_KEY
STRIPE_SIGNING_SECRET
BRAINTREE_MERCHANT_ID
BRAINTREE_PUBLIC_KEY
BRAINTREE_PRIVATE_KEY
BRAINTREE_ENVIRONMENT
PADDLE_VENDOR_ID
PADDLE_VENDOR_AUTH_CODE
PADDLE_PUBLIC_KEY_BASE64
PADDLE_ENVIRONMENT
If you want to modify the Stripe SCA template or any other views, you can copy over the view files using:
bin/rails generate pay:views
If you want to modify the email templates, you can copy over the view files using:
bin/rails generate pay:email_views
Emails can be enabled/disabled using the send_emails
configuration option (enabled by default).
When enabled, the following emails will be sent when:
- A charge succeeded
- A charge was refunded
- A yearly subscription is about to renew
Need to make some changes to how Pay is used? You can create an initializer config/initializers/pay.rb
Pay.setup do |config|
# For use in the receipt/refund/renewal mailers
config.business_name = "Business Name"
config.business_address = "1600 Pennsylvania Avenue NW"
config.application_name = "My App"
config.support_email = "helpme@example.com"
config.send_emails = true
config.default_product_name = "default"
config.default_plan_name = "default"
config.automount_routes = true
config.routes_path = "/pay" # Only when automount_routes is true
# All processors are enabled by default. If a processor is already implemented in your application, you can omit it from this list and the processor will not be set up through the Pay gem.
config.enabled_processors = [:stripe, :braintree, :paddle]
end
If a user's email is updated, Pay will enqueue a background job (CustomerSyncJob
) to sync the email with the payment processors they have setup.
It is important you set a queue_adapter for this to happen. If you don't, the code will be executed immediately upon user update. More information here
# config/application.rb
config.active_job.queue_adapter = :sidekiq
See Customers