Skip to content

jfturcot/solidus_paysafe

Repository files navigation

Solidus Paysafe

CircleCI codecov

Solidus extension to integrate Paysafe as a payment provider.

Installation

Add solidus_paysafe to your Gemfile:

gem 'solidus_paysafe'

Bundle your dependencies and run the installation generator:

bin/rails generate solidus_paysafe:install

Add the paysafe.js script to the head of your HTML:

<script src="https://hosted.paysafe.com/js/v1/latest/paysafe.min.js"></script>

Usage

Navigate to Settings > Payments > Payment Methods in the admin panel. You can now create a new payment method that uses Paysafe by selecting Paysafe under Type in the New Payment Method form and saving. The Paysafe payment method's extra fields will be now shown in the form.

Configure via database configuration

If you want to store your Paysafe credentials in the database just fill the new fields in the form, selecting custom (default) in the Preference Source field.

Configure via static configuration

If you want to store your credentials into your codebase or use ENV variables you can create the following static configuration:

# config/initializers/spree.rb

Spree.config do |config|
  # ...

  # The following example uses Rails credentials, you can also use ENV variables instead.
  config.static_model_preferences.add(
    SolidusPaysafe::PaymentMethod,
    'paysafe_env_credentials',
    test_mode: Rails.application.credentials.dig(:paysafe, :test_mode),
    api_key: Rails.application.credentials.dig(:paysafe, :api_key),
    api_secret: Rails.application.credentials.dig(:paysafe, :api_secret),
    account_number: Rails.application.credentials.dig(:paysafe, :account_number),
    single_use_token_key: Rails.application.credentials.dig(:paysafe, :single_use_token_key),
    single_use_token_secret: Rails.application.credentials.dig(:paysafe, :single_use_token_secret)
  )
end

Once your server has been restarted, you can select in the Preference Source field a new entry called paysafe_env_credentials. After saving, your application will start using the static configuration to process Paysafe payments.

Development

Testing the extension

First bundle your dependencies, then run bin/rake. bin/rake will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using bin/rake extension:test_app.

bin/rake

To run Rubocop static code analysis run

bundle exec rubocop

When testing your application's integration with this extension you may use its factories. Simply add this require statement to your spec/spec_helper.rb:

require 'solidus_paysafe/testing_support/factories'

Or, if you are using FactoryBot.definition_file_paths, you can load Solidus core factories along with this extension's factories using this statement:

SolidusDevSupport::TestingSupport::Factories.load_for(SolidusPaysafe::Engine)

Running the sandbox

To run this extension in a sandboxed Solidus application, you can run bin/sandbox. The path for the sandbox app is ./sandbox and bin/rails will forward any Rails commands to sandbox/bin/rails.

Here's an example:

$ bin/rails server
=> Booting Puma
=> Rails 6.0.2.1 application starting in development
* Listening on tcp://127.0.0.1:3000
Use Ctrl-C to stop

Updating the changelog

Before and after releases the changelog should be updated to reflect the up-to-date status of the project:

bin/rake changelog
git add CHANGELOG.md
git commit -m "Update the changelog"

Releasing new versions

Please refer to the dedicated page on Solidus wiki.

License

Copyright (c) 2021 [name of extension author], released under the New BSD License.

About

Solidus extension for Paysafe payment provider

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published