Comments (13)
This gem looks so promising - shame there is such a lack of information. Would love to use this for Sagepay but there doesn't seem to be any useful documentation at all. Even 2 years after the initial request there's nothing. Such a shame.
from offsite_payments.
Well, i've managed with it, so here is a little example. To tell the truth some examples of using ActiveMerchant would fit the needs.
First of all, create a configuration (config/offsite_payments.yml) file with passwords and options for ur pay method. I use russian payment system robokassa:
robokassa:
test_mode: false
login: your_login
password1: "pas1"
password2: "pas2"
Then create an initializer (config/initializers/offsite_payments.rb):
require 'offsite_payments'
require 'offsite_payments/action_view_helper'
ActionView::Base.send(:include, OffsitePayments::ActionViewHelper)
OffsitePayments.mode = :test # for testing server
Rails.configuration.offsite_payments = YAML.load_file("#{Rails.root}/config/offsite_payments.yml")
Then you need to create a controller, which would get an incoming request from payment system to mark a payment as successful or not:
class RobokassaController < ApplicationController
# Robokassa call this action after transaction
def paid
create_notification 'password2'
if @notification.acknowledge # check if itβs genuine Robokassa request
@order.approve! # project-specific code
render text: @notification.success_response
else
head :bad_request
end
end
def success
create_notification 'password1'
if @notification.acknowledge
@order.approve!
redirect_to user_home_path, notice: 'Successful payment'
else
render text: 'fraud'
end
end
def fail
redirect_to user_home_path, notice: 'Payment failed.'
end
private
def create_notification(password)
@notification = OffsitePayments.integration(:robokassa).notification(request.raw_post, secret: Rails.configuration.offsite_payments['robokassa'][password])
find_payment
end
def find_payment
@order = Order.find(@notification.item_id)
end
end
Then add some routes:
scope 'robokassa' do
post 'paid' => 'robokassa#paid', as: :robokassa_paid
post 'success' => 'robokassa#success', as: :robokassa_success
post 'fail' => 'robokassa#fail', as: :robokassa_fail
end
and use a helper to create a pay button where you need it on your site:
<%= payment_service_for order.id, Rails.configuration.offsite_payments['robokassa']['login'],
amount: @order.price,
service: :robokassa,
secret: Rails.configuration.offsite_payments['robokassa']['password1'] do |s| %>
<%= submit_tag "Pay!", class: 'button blue', style: 'padding-bottom: 3px;' %>
<% end %>
Or if you work on for example backbone application, and need to render pay button in backbone template, you can pass to backbone model a payment signature, generated on a server side and use it in javascript helper:
def robokassa_signature
OffsitePayments.integration(:robokassa).helper(
id,
Rails.configuration.offsite_payments['robokassa']['login'],
amount: price,
secret: Rails.configuration.offsite_payments['robokassa']['password1']
).generate_signature
end
Good luck!
from offsite_payments.
I wrote a small tutorial on my ongoing experience on building the integration: https://coderwall.com/p/dqed4a/how-to-create-a-payment-gateway-for-offsite_payments-active_merchant.
from offsite_payments.
+1
from offsite_payments.
+1
from offsite_payments.
It's unfortunate that this requires Rails and doesn't work with Sinatra. Thanks for the example @madmike
from offsite_payments.
It doesn't require Rails, you could use it with any framework you like, just write your own view helper using OffsitePayments.integration(:payment_system).helper method
from offsite_payments.
Interesting, I get this error when trying to fire up a sinatra app that requires offsite_payments
:
undefined method `class_attribute' for ActiveMerchant::PostData:Class (NoMethodError)
EDIT: Oh this goes away when requiring active_merchant
. This should probably also be documented.
from offsite_payments.
@pawel2105 offsite_payments
no longer depends on active_merchant, so that issue should be fixed now.
from offsite_payments.
thanks @madmike your example helped me in integrating payu_in.
from offsite_payments.
@wvanbergen @madmike offsite_payments
requires ActiveSupport, and also actionpack, so yeah it still depends on a lot of Rails libraries.
from offsite_payments.
@madmike @lulalala As you can see the error happens on ActiveMerchant::PostData
, i.e. ActiveMerchant not OffsitePayments. The link between these two libraries was severed a while ago, so if you see the class_attribute
error while you are not using ActiveMerchant yourself directly, you're probably on an old version of OffsitePayments.
Both libraries still depend on ActiveSupport, and OffsitePayments depends on ActionPack as well.
from offsite_payments.
I generated form using payment_service_for and it successfully submits to payu_in gateway. Now I got a different requirement. I want to perform below validation on "submit" button
- want to validate that item is still available to buy
- want to save booking if validate success.
After these two actions, automatically my form should submit to integration service.
Thus instead of generating html form using payment_service_for, is it possible to redirect_to gateway with params from rails controller itself ? There should be a method to achieve this task from the ruby code itself instead of html form post
from offsite_payments.
Related Issues (20)
- IntegrationGenerator wrong tests directory
- Offsite Payments Maintenance HOT 4
- Consider more appropriate error classes for networking or gateway failures
- Changed URL ROBOKASSA HOT 1
- Why does Realex integration add a timestamp to order id? HOT 1
- Implement Coinbase v2 API
- Customize a string sent to Valitor HOT 6
- Release recent gem version HOT 3
- offsite_payments 3.0 request for comments HOT 1
- Skrill API url HOT 1
- HiTrust doesn't use ISO4217 definition of TWD
- Log form output to improve debugging
- follow-up: update reason1 field per sofort request
- [Paytm] Checkout with phone leads to error HOT 2
- Update README inregards to integrations
- mollie test issuer
- Payfast Passphrase issue HOT 4
- Modify supported Rails versions
- Internacionalization: Translation of labels
- fields is not populated on the initialize method of an implementation.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from offsite_payments.