Skip to content

Instantly share code, notes, and snippets.

@AnotherJoSmith
Last active August 29, 2015 14:23
Show Gist options
  • Save AnotherJoSmith/8245dbebeb99460b6a0e to your computer and use it in GitHub Desktop.
Save AnotherJoSmith/8245dbebeb99460b6a0e to your computer and use it in GitHub Desktop.
Signature calculation with fixed fields map
require 'openssl'
# ORIGINAL POST
#utf8=✓&authenticity_token=XfrbzgrdzxQvjqXcV+sVJrW0xsGesNlW99XliCYVU/s=&x_reference=2097875269&x_account_id=1&x_amount=32.20&x_currency=AUD&x_url_callback=https://checkout.shopify.com/services/ping/notify_integration/universal/7991271&x_url_complete=https://checkout.shopify.com/7991271/checkouts/b4c2f5e4966659b43e6210d0d34bac5a/offsite_gateway_callback&x_shop_country=AU&x_shop_name=zipMoney&x_test=true&x_customer_first_name=tznvrdgb&x_customer_last_name=tznvrdgb&x_customer_email=tznvrdgb@sharklasers.com&x_customer_phone=0416407267&x_customer_shipping_country=AU&x_customer_shipping_first_name=tznvrdgb&x_customer_shipping_last_name=tznvrdgb&x_customer_shipping_city=Mosman&x_customer_shipping_address1=2 / 15 Esplanade &x_customer_shipping_address2=apt&x_customer_shipping_state=NSW&x_customer_shipping_zip=2088&x_customer_shipping_phone=0416407267&x_invoice=#2097875269&x_amount_shipping=0.00&x_amount_tax=0.00&x_description=zipMoney - #2097875269&x_url_cancel=http://zipmoney.myshopify.com/cart&x_signature=5fb18d05e24d08b1c94037dd4ce3474912f53568e5b6a7898b94a76980d02d3f
fields = {
:x_reference => '2097875269',:x_account_id => '1',:x_amount => '32.20', :x_currency => 'AUD',
:x_url_callback=>'https://checkout.shopify.com/services/ping/notify_integration/universal/7991271',
:x_url_complete=> 'https://checkout.shopify.com/7991271/checkouts/b4c2f5e4966659b43e6210d0d34bac5a/offsite_gateway_callback',
:x_shop_country=>'AU',:x_shop_name=>'zipMoney',:x_test=>'true', :x_customer_first_name=>'tznvrdgb',
:x_customer_last_name=>'tznvrdgb', :x_customer_email=>'tznvrdgb@sharklasers.com', :x_customer_phone=>'0416407267',
:x_customer_shipping_country=>'AU', :x_customer_shipping_first_name=>'tznvrdgb', :x_customer_shipping_last_name=>'tznvrdgb',
:x_customer_shipping_city=>'Mosman', :x_customer_shipping_address1=>'2 / 15 Esplanade ',
:x_customer_shipping_address2=>'apt', :x_customer_shipping_state=>'NSW', :x_customer_shipping_zip=>'2088',
:x_customer_shipping_phone=>'0416407267', :x_invoice=>'#2097875269', :x_amount_shipping=>'0.00',
:x_amount_tax=>'0.00', :x_description=>'zipMoney - #2097875269',:x_url_cancel=>'http://zipmoney.myshopify.com/cart'
}
message = fields.sort.join
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), 'iU44RWxeik', message)
sent_x_signature='5fb18d05e24d08b1c94037dd4ce3474912f53568e5b6a7898b94a76980d02d3f'
puts signature == sent_x_signature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment