Skip to content

Instantly share code, notes, and snippets.

@kamal
Created July 5, 2010 16:38
Show Gist options
  • Save kamal/464515 to your computer and use it in GitHub Desktop.
Save kamal/464515 to your computer and use it in GitHub Desktop.
# config/environment.rb
config.gem "bitfluent-activemerchant", :lib => "activemerchant"
# config/initializers/ipay88.rb
ActiveMerchant::Billing::Integrations::Ipay88.merchant_key = "t6mqZRi6UB"
require 'active_merchant/billing/integrations/action_view_helper'
ActionView::Base.send(:include, ActiveMerchant::Billing::Integrations::ActionViewHelper)
# app/controllers/orders_controller.rb
class OrdersController < ApplicationController
def pay
@order = Order.find(params[:id])
end
def return
ret = ActiveMerchant::Billing::Integrations::Ipay88.return(request.raw_post)
if ret.success?
@order = Order.find(ret.order)
@order.capture!(:amount => ret.amount)
flash[:notice] = "Thanks for the payment!"
else
flash[:error] = "Payment was unsuccessful: #{ret.error}"
end
end
end
<form action="https://www.mobile88.com/epayment/entry.asp" method="post">
<input id="RefNo" name="RefNo" type="hidden" value="1" />
<input id="UserContact" name="UserContact" type="hidden" value="0128888888" />
<input id="UserName" name="UserName" type="hidden" value="Kamal" />
<input id="Signature" name="Signature" type="hidden" value="dpBSyeFdjmlLug36ao1HsIwNoW0=" />
<input id="UserEmail" name="UserEmail" type="hidden" value="[email protected]" />
<input id="Amount" name="Amount" type="hidden" value="10.00" />
<input id="ProdDesc" name="ProdDesc" type="hidden" value="Bioshock 2 and Portal" />
<input id="Currency" name="Currency" type="hidden" value="MYR" />
<input id="MerchantCode" name="MerchantCode" type="hidden" value="YOUR-IPAY88-MERCHANT-CODE" />
</form>
<% payment_service_for @order.id, 'YOUR-IPAY88-MERCHANT-CODE',
:amount => @order.total,
:currency => 'MYR',
:service => :ipay88 do |service| %>
<% service.customer :name => @order.customer_name,
:email => @order.customer_email,
:phone => @order.customer_phone %>
<% service.description @order.items.to_sentence %>
<% end %>
# config/routes.rb
ActionController::Routing::Routes.draw do |map|
map.resources :orders, :member => { :pay => :get }, :collection => { :return => :post }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment