Last active
December 24, 2015 02:19
-
-
Save barockok/6729605 to your computer and use it in GitHub Desktop.
Sample code for implementation vt-web with activemerchant
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
merchant_id = 'XXXXXXXXXXXXXXXXXXX' | |
merchant_hash_key = 'XXXXXXXXXXXXXXXXXXX' | |
# implemetation for generating form | |
payment_service_for @order.id, merchant_id, \ | |
merchant_hash_key: merchant_hash_key, | |
service: :veritrans, | |
amount: @order.total_amount, | |
currency: 'IDR', | |
html: {:id => 'payment-form' , :authenticity_token => false } do |service| | |
service.cancel_url = "http://example.com/cancel" | |
service.error_url = "http://example.com/error" | |
service.return_url = "http://example.com/return" | |
service.customer first_name: @order.billing_first_name, | |
last_name: @order.billing_last_name, | |
address_1: @order.billing_address_1, | |
address_2: @order.billing_address_2, | |
city: @order.billing_city, | |
zip: @order.billing_postal_code, | |
phone: @order.billing_phone, | |
country_code: 'IDN', | |
email: '[email protected]' | |
service.shipping first_name: @order.shipping_first_name, | |
last_name: @order.shipping_last_name, | |
address_1: @order.shipping_address_1, | |
address_2: @order.shipping_address_2, | |
city: @order.shipping_city, | |
zip: @order.shipping_postal_code, | |
phone: @order.shipping_phone, | |
country_code: 'IDN' | |
@order.order_items.each do |item| | |
service.items << {id: item.product_id, | |
price: item.price, | |
qty: item.qty, | |
name: item.product_name} | |
end | |
# implemetation for handle notification | |
@notification = ActiveMerchant::Billing::Integrations::Veritrans::Notification.new request.raw_post \ | |
merchant_id: merchant_id, | |
mecrhant_hash_key: merchant_hash_key | |
@order.paid! if @notification.acknowledge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So how to use it? :)