Active Merchant Integrations have not been documented that well, so I decided to document my current understanding of it here. Please feel free to contribute your thoughts.
When to use integration instead of gateway
Basically always when your payment method means that the user leaves to a remote site to complete the payment.
Step by step guide to create a new integration
Generation
Checkout Active Merchant from Github
Run:
script/generate integration YourIntegration
This will create few files:
lib/active_merchant/billing/integrations/YourIntegration.rb lib/active_merchant/billing/integrations/YourIntegration/helper.rb lib/active_merchant/billing/integrations/YourIntegration/notification.rb test/unit/integrations/YourIntegration_module_test.rb test/unit/integrations/helpers/YourIntegration_helper_test.rb test/unit/integrations/notifications/YourIntegration_notification_test.rb
Integration Module (lib/active_merchant/billing/integrations/YourIntegration.rb)
Here you can configure module wide stuff such as service_url and what is sent to Notification class.
Helper (lib/active_merchant/billing/integrations/YourIntegration/helper.rb)
Here you configure how the payment form is created.
1. Initialize - initialize the form, insert hidden fields, fetch the md5secret
2. Mappings - defines form fields and field mappings between ActiveMerchant and your payment provider
3. form_fields - actions you might want to do after form is generated, such as calculate checksums
Notification (lib/active_merchant/billing/integrations/YourIntegration/notification.rb)
Notification is called when the user comes back to site (return_url). Check the app example later.
First you need to again map received parameters (your payment provider -> ActiveMerchant).
Then depending on the request type (POST/GET) you need to parse the request accordingly and then acknowledge the notification. In our case (LINK LINK) this means calculating the checksum and check that it matches with the one got from payment provider.
Testing
Testing is pretty straight forward. Check our examples here:
Your app
Integration to your app has three parts
Settings - you probably want to set your payment provider details (merchant_id and authcode in our case) in an initializer.
View - then you need implement the view for payment. This is done with the payment_service_for validator. In our case it looks something like this (non-dynamic product):
And then finally the controller part. For the return url you need a matching action:
That’s it :) If you do create your own integration, please create a pull request for ActiveMerchant. Instructions here: https://github.com/Shopify/active_merchant/wiki/Contributing
- Antti






