Paytrail client for the Paytrail API. Please refer to the Paytrail documentation for more information.
Add this line to your application's Gemfile:
gem 'paytrail-client'
require 'paytrail-client'
# Configure the client with your merchant credentials
PaytrailClient.configure do |config|
config.merchant_id = 12345
config.merchant_secret = 'your_merchant_secret'
end
# Call Paytrail API for a payment token.
# The client supports passing the object keys as snake_case or camelCase.
token = PaytrailClient::Payment.create(order_number: '1234',
currency: 'EUR',
locale: 'en_US',
url_set: {
success: 'http://www.example.org/success',
failure: 'http://www.example.org/failure',
notification: 'http://www.example.org/notification'
},
price: 100.50)
# Redirect to received url
redirect_to(token['url'])
# Verify payment
begin
PaytrailClient::Payment.verify_payment!(
params['ORDER_NUMBER'],
params['TIMESTAMP'],
params['PAID'],
params['METHOD'],
params['RETURN_AUTHCODE'])
puts 'Payment verified'
rescue PaytrailClient::InvalidPaymentError
puts 'Could not verify payment'
end
Bug reports and pull requests are welcome on GitHub at https://github.com/antmanj/paytrail-client.
The gem is available as open source under the terms of the MIT License.