Created
September 22, 2015 05:08
-
-
Save tristanm/e7a1974d489a91206316 to your computer and use it in GitHub Desktop.
Oversimplified example of using Offsite Payments and PxPay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%# Example of using OffsitePayments::ActionViewHelper to generate a form %> | |
<%= payment_service_for 'ORD123456', '[user id]', service: :pxpay, return_url: 'http://localhost:3000/pxpay/return', credential2: '[key]', currency: 'NZD', amount: 12.34 do |service| %> | |
<%= submit_tag 'Pay Now' %> | |
<% end %> | |
<%# Example of generating a URL directly (see controller) %> | |
<%= link_to @service.credential_based_url, @service.credential_based_url %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/offsite_payments.rb | |
require 'offsite_payments' | |
ActionView::Base.send(:include, OffsitePayments::ActionViewHelper) | |
# OffsitePayments.mode = :test # for testing server | |
module OffsitePayments::Integrations::Pxpay | |
# Use PxPay 2.0 | |
def self.token_url | |
'https://sec.paymentexpress.com/pxaccess/pxpay.aspx' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DummyPxpayController < ApplicationController | |
layout false | |
def new | |
# Uses OffsitePayments::Helper directly rather than using the | |
# OffsitePayments::ActionViewHelper (see view) | |
@service = OffsitePayments::Integrations::Pxpay::Helper.new( | |
'ORD123456', | |
'[user id]', | |
credential2: '[key]', | |
amount: 12.34, | |
currency: 'NZD', | |
return_url: 'http://localhost:3000/pxpay/return' | |
) | |
end | |
def return | |
# Example of checking for success (this is the return URL as per #new) | |
@notification = OffsitePayments::Integrations::Pxpay.notification( | |
request.query_string, | |
credential1: '[user id]', | |
credential2: '[key]' | |
) | |
render text: @notification.success? ? 'success' : 'fail' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
get 'pxpay/new' => 'dummy_pxpay#new' | |
get 'pxpay/return' => 'dummy_pxpay#return' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment