Giter Site home page Giter Site logo

Comments (13)

ums-uk avatar ums-uk commented on June 15, 2024 7

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.

madmike avatar madmike commented on June 15, 2024 3

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.

lakesare avatar lakesare commented on June 15, 2024 2

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.

groe avatar groe commented on June 15, 2024

+1

from offsite_payments.

madmike avatar madmike commented on June 15, 2024

+1

from offsite_payments.

pawel2105 avatar pawel2105 commented on June 15, 2024

It's unfortunate that this requires Rails and doesn't work with Sinatra. Thanks for the example @madmike

from offsite_payments.

madmike avatar madmike commented on June 15, 2024

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.

pawel2105 avatar pawel2105 commented on June 15, 2024

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.

wvanbergen avatar wvanbergen commented on June 15, 2024

@pawel2105 offsite_payments no longer depends on active_merchant, so that issue should be fixed now.

from offsite_payments.

vijay-meena avatar vijay-meena commented on June 15, 2024

thanks @madmike your example helped me in integrating payu_in.

from offsite_payments.

lulalala avatar lulalala commented on June 15, 2024

@wvanbergen @madmike offsite_payments requires ActiveSupport, and also actionpack, so yeah it still depends on a lot of Rails libraries.

from offsite_payments.

wvanbergen avatar wvanbergen commented on June 15, 2024

@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.

vijay-meena avatar vijay-meena commented on June 15, 2024

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

  1. want to validate that item is still available to buy
  2. 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.