0.0
No commit activity in last 3 years
No release in over 3 years
Ruby wrapper for Mandarin Pay API aimed to make Mandarin Pay integration even more easier
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.4.0
>= 1.3.0, ~> 1.3

Runtime

<= 5.1, >= 4.0.0
 Project Readme

The MandarinPay gem

by Drakmail

Ruby wrapper for MandarinPay API. Make Mandarin Pay to work with your Rails project without pain. MandarinPay took the best from rubykassa gem and Active Merchant Robokassa integration but easier to use and setup.

Installation

Add to your Gemfile:

gem "mandarin_pay"

Usage

Run rails g mandarin_pay:install, get an initializer with the following code:

MandarinPay.configure do |config|
  config.merchant_id = ENV["MANDARINPAY_MERCHANT_ID"]
  config.sharedsec = ENV["MANDARINPAY_SHAREDSEC"]

  # Result callback is called in MandarinPayController#paid action if valid signature
  # was generated. It should always return "OK#{ invoice_id }" string, so implement
  # your custom logic above `render text: notification.success` line

  config.result_callback = ->(notification) { render text: notification.success }

  # Define success or failure callbacks here like:

  # config.success_callback = ->(notification) { render text: 'success' }
  # config.fail_callback = ->(notification) { redirect_to root_path }
end

and configure it with your credentials.

Also, you need to specify Result URL, Success URL and Fail URL at the "Technical Settings" (Технические настройки) in your MandarinPay dashboard:

  • Result URL: http://<your_domain>/mandarin_pay/paid
  • Success URL: http://<your_domain>/mandarin_pay/success
  • Fail URL: http://<your_domain>/mandarin_pay/fail

To define custom success/fail callbacks you can also use the initializer:

MandarinPay.configure do |config|
  ...
  config.success_callback = ->(notification) { render text: 'success' }
  config.fail_callback    = ->(notification) { redirect_to root_path }
  config.result_callback  = ->(notification) { render text: notification.success }
end

Lambdas are called in MandarinPayController so you can respond with any kind that is supported by Rails.

NOTE: result_callback should always return "OK" string. So, implement your custom logic above render text: notification.success line.

Once you are done, simply use pay_form helper in your view:

<%= pay_form "Pay with Mandarin Pay", "invoice_number", 20.00 %>

Additionally you may want to pass extra options. There is no problem:

<%= pay_form "Pay with Mandarin Pay", "invoice_number", 20.00, customer_email: "user@example.com", class: "btn btn-succses", form_class: "mp-form" %>

Supported Rubies and Rails versions

Rubies:

  • 2.0.0
  • 2.1.0
  • 2.2.0
  • 2.3.0

Rails:

  • ~> 4.0.0
  • ~> 4.1.0
  • ~> 4.2.0

License

This project rocks and uses MIT-LICENSE Copyright (c) 2016 Drakmail