Skip to content
This repository was archived by the owner on Apr 28, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
a73e887
Update Readme File
Sep 3, 2014
11e13f0
Add initial test to make Circle happy so we can :shipit:
j-mutter Sep 3, 2014
859ed44
Merge pull request #8 from Shopify/initial-test
j-mutter Sep 4, 2014
aefc278
update instructions & reference signature calculator
Sep 17, 2014
5c37414
small tweaks
Sep 17, 2014
9aa8d72
Merge pull request #9 from Shopify/update_readme
Sep 19, 2014
738ff73
http -> https
Sep 29, 2014
6174c5a
fix timestamp typo
Oct 1, 2014
4e8194a
Merge pull request #10 from Shopify/timespamp
Oct 2, 2014
3c9627f
update Readme
Nov 21, 2014
8145ba4
Updates Offsit-Sim setup instructions
mhashemi86 Nov 28, 2014
839262e
Updates setup instructions
mhashemi86 Nov 28, 2014
670522b
Fixes copy
mhashemi86 Nov 28, 2014
626da66
Update README.md
mhashemi86 Dec 12, 2014
8876764
Merge pull request #11 from Shopify/update-instructions
mhashemi86 Dec 17, 2014
25c7866
change to a correct signature
andrewpaliga Feb 26, 2015
6fcce11
Merge pull request #12 from Shopify/correct_signature
andrewpaliga Feb 26, 2015
69bb354
Add base_path such that assets work when mounted
cjoudrey Mar 20, 2015
04a45e5
Merge pull request #13 from Shopify/mountable-offsite-gateway-sim
volmer Mar 25, 2015
dd9a302
Add text for transaction timestamp
andrewpaliga Apr 30, 2015
0754ec1
Merge pull request #14 from Shopify/timestamp_readme
andrewpaliga Apr 30, 2015
54b5195
updating logo info
andrewpaliga May 20, 2015
0e15739
remove
andrewpaliga May 20, 2015
9914833
Merge pull request #15 from Shopify/update_logo_text
andrewpaliga May 20, 2015
8583989
Updating rack gem
AnotherJoSmith Jun 17, 2015
896380a
Merge pull request #17 from Shopify/update-rack-gem
AnotherJoSmith Jun 17, 2015
f5d28cb
additional steps for payment providers
andrewpaliga Jun 29, 2015
2f51b46
update text
andrewpaliga Jun 29, 2015
5a2fcd2
Merge pull request #18 from Shopify/add_more_steps
andrewpaliga Jun 30, 2015
e403aca
updating for Hosted Payment SDK
andrewpaliga Aug 26, 2015
7eb598c
Merge pull request #19 from Shopify/update_to_hosted_payment_simulator
andrewpaliga Aug 26, 2015
0a1c3c0
text change
andrewpaliga Aug 31, 2015
76c637e
add incontext test page
andrewpaliga Oct 16, 2015
10046cb
Merge pull request #20 from Shopify/add_incontext
andrewpaliga Oct 16, 2015
7701bdd
Add the new billing request fields
Mar 2, 2016
eb74d02
Merge pull request #23 from Shopify/update_request_fields
ShayneP Mar 9, 2016
22c96f8
Update stack to Cedar-14 in order to push new changes.
jamiemtdwyer Mar 17, 2016
9d88381
Updated Ruby version in Gemfile to be compatible with Cedar-14
jamiemtdwyer Mar 17, 2016
3ea4336
add support for dev
aprofeit Mar 24, 2016
118c02b
Merge pull request #24 from Shopify/dev-support
Mar 24, 2016
6f77e83
[dev.yml] automated update by dev-map
burke Apr 20, 2016
2e6cd82
Create service.yml
shopify-services Apr 27, 2016
ce5f5cc
update dev.yml
burke May 25, 2016
4230efb
Update README.md
kennethlombardi Jun 19, 2016
76fadc6
Integrate stakeholder feedback
kennethlombardi Jun 24, 2016
7781524
Merge pull request #26 from Shopify/grammar-fix
andrewpaliga Jun 24, 2016
e5fa597
Update service.yml
lyverovski Jul 11, 2016
2856958
Update service.yml
lyverovski Jul 11, 2016
1f75cda
Update service.yml
lyverovski Jul 11, 2016
6e71efe
[dev.yml] automated update by dev-map
jules2689 Aug 11, 2016
895cb76
add x_message field
jordanliddle Sep 13, 2016
1af3d89
Merge pull request #28 from Shopify/add-message-field
jordanliddle Sep 20, 2016
f7aa0b1
fix calculator styling
jordanliddle Sep 22, 2016
69b54ea
Merge pull request #29 from Shopify/fix-styling
jordanliddle Sep 23, 2016
de74765
Fixes link to docs on creating a dev store
reggieb Sep 29, 2016
239a3e6
Fix for billing address label
marc-roberts-cko Oct 7, 2016
64af5d9
Merge pull request #30 from reggieb/fix_readme_link
pi3r Oct 14, 2016
24f5a2e
Update service.yml
etiennebarrie Oct 24, 2016
12a99b3
adds /capture and /refund endpoint + some refactor
Oct 24, 2016
bf0b6dc
Merge pull request #33 from Shopify/hpsdk-refund-capture
pi3r Nov 16, 2016
3f0b797
Adding hosted-payment-sim.myshopify.io to dev.yml
Krystosterone Jan 9, 2017
9d298e8
Merge pull request #36 from Shopify/adding-url-to-dev
Krystosterone Jan 9, 2017
be991dc
adds new tests to simulator
jordanliddle Nov 18, 2016
5415c4f
refactor
jordanliddle Dec 13, 2016
923d7cd
Merge pull request #34 from Shopify/add-tests
jordanliddle Jan 11, 2017
b236d53
Add new request field x_shopify_order_id
bradsokol Jul 12, 2017
cea1f17
Merge pull request #37 from Shopify/add-shopify-order-id-to-calculator
bradsokol Jul 12, 2017
2ae43ad
add support for order management notification
Jan 6, 2017
fc02209
Merge pull request #39 from Shopify/async-notification
pi3r Jul 26, 2017
f07aa7f
Update rubyzip to 1.2.1
Jul 27, 2017
0445d19
Merge pull request #43 from Shopify/update-rubyzip
pi3r Jul 27, 2017
a0140a7
Remove heroku gem from the deploy group
Jul 27, 2017
3dc5282
Merge pull request #44 from Shopify/remove-heroku-gem
pi3r Jul 27, 2017
52b8d39
[#railgun] migrate configuration to 2.0+ format (1/2)
shopify-admins Sep 12, 2017
2c3375b
[#railgun] migrate configuration to 2.0+ format (2/2)
shopify-admins Sep 12, 2017
20d78e7
Merge pull request #31 from marc-roberts-cko/fix-shipping-label
bdewater Sep 13, 2017
e0ad700
[bot] remove unused 'packages' dev.yml element [skip ci]
Dec 4, 2017
9977223
Update readme to use the new shopifycloud url
pi3r May 3, 2018
993afa9
Update rack-protection to 1.5.5
shopify-services Jun 28, 2018
375ee25
Merge pull request #51 from Shopify/services-db/update-rack-protectio…
AnotherJoSmith Jun 28, 2018
e569657
Remove services.yml and shipit.yml
Jun 28, 2018
90677cd
Update ruby to v2.5.3
Jan 22, 2019
533cfed
Replace Digest by OpenSSL library
Jan 22, 2019
b291334
Merge pull request #53 from Shopify/update-ruby-version-2-5-3
Jan 22, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ tmp
.yardoc
_yardoc
doc/
.tool-versions
.idea/*
10 changes: 6 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source 'http://rubygems.org'
ruby '2.1.1'
source 'https://rubygems.org'
ruby '2.5.3'

gem 'sinatra'
gem 'httparty'
Expand All @@ -9,6 +9,8 @@ gem 'addressable'
group :development do
gem 'byebug'
end
group :deploy do
gem 'heroku', '~> 3.8.2'

group :test do
gem 'test-unit'
gem 'rack-test'
end
75 changes: 37 additions & 38 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
GEM
remote: http://rubygems.org/
remote: https://rubygems.org/
specs:
addressable (2.3.5)
byebug (2.7.0)
columnize (~> 0.3)
debugger-linecache (~> 1.2)
columnize (0.3.6)
debugger-linecache (1.2.0)
excon (0.37.0)
heroku (3.8.3)
heroku-api (~> 0.3.17)
launchy (>= 0.3.2)
netrc (~> 0.7.7)
rest-client (~> 1.6.1)
rubyzip
heroku-api (0.3.18)
excon (~> 0.27)
multi_json (~> 1.8)
httparty (0.10.0)
multi_json (~> 1.0)
multi_xml
json (1.8.1)
launchy (2.4.2)
addressable (~> 2.3)
mime-types (2.3)
multi_json (1.10.1)
multi_xml (0.5.5)
netrc (0.7.7)
rack (1.5.2)
rack-protection (1.5.2)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
byebug (10.0.2)
httparty (0.16.3)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
json (2.1.0)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2018.0812)
minitest (5.11.3)
multi_xml (0.6.0)
mustermann (1.0.3)
power_assert (1.1.1)
public_suffix (3.0.3)
rack (2.0.6)
rack-protection (2.0.5)
rack
rest-client (1.6.7)
mime-types (>= 1.16)
rubyzip (1.1.4)
sinatra (1.4.4)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
tilt (1.4.1)
rack-test (1.1.0)
rack (>= 1.0, < 3)
sinatra (2.0.5)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.5)
tilt (~> 2.0)
test-unit (3.2.7)
power_assert
tilt (2.0.9)

PLATFORMS
ruby

DEPENDENCIES
addressable
byebug
heroku (~> 3.8.2)
httparty
json
minitest
rack-test
sinatra
test-unit

RUBY VERSION
ruby 2.5.3p105

BUNDLED WITH
1.17.3
121 changes: 11 additions & 110 deletions README.md

Large diffs are not rendered by default.

71 changes: 54 additions & 17 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@

class OffsiteGatewaySim < Sinatra::Base

def initialize
def initialize(base_path: '')
@base_path = base_path
@key = 'iU44RWxeik'
super
end

def fields
@fields ||= request.params.select {|k, v| k.start_with? 'x_'}
@fields ||= if request.content_type == 'application/json'
JSON.load(request.body.read)
else
request.params.select { |k, v| k.start_with?('x_') }
end
end

def request_fields
Expand All @@ -26,29 +31,52 @@ def response_fields
end

def sign(fields, key=@key)
Digest::HMAC.hexdigest(fields.sort.join, key, Digest::SHA256)
OpenSSL::HMAC.hexdigest("SHA256", key, fields.sort.join)
end

def signature_valid?
provided_signature = fields['x_signature']
expected_signature = sign(fields.reject{|k,_| k == 'x_signature'})
provided_signature && provided_signature.casecmp(expected_signature) == 0
end

get '/' do
erb :get, :locals => {key: @key}
erb :get, :locals => { key: @key }
end

post '/' do
provided_signature = fields['x_signature']
expected_signature = sign(fields.reject{|k,_| k == 'x_signature'})
signature_ok = provided_signature && provided_signature.casecmp(expected_signature) == 0
erb :post, :locals => {signature_ok: signature_ok}
erb :post, :locals => { signature_ok: signature_valid? }
end

post '/incontext' do
erb :incontext, :locals => { signature_ok: signature_valid? }
end

get '/calculator' do
erb :calculator, :locals => {
request_fields: request_fields,
response_fields: response_fields,
signature: sign(fields.delete_if { |_, v| v.nil? }, params['secret_key'] || @key)
signature: sign(fields.delete_if { |_, v| v.empty? }, params['secret_key'] || @key)
}
end

post '/execute/:action' do |action|
post %r{/(capture|refund|void)} do |action|
content_type :json

if signature_valid?
[200, {}, fields.merge(x_result: 'pending',
x_gateway_reference: SecureRandom.hex,
x_timestamp: Time.now.utc.iso8601).to_json]
else
[401, {}, { x_status: 'failed', x_error_message: 'Invalid signature' }.to_json]
end
end

get '/notification' do
erb :notification
end

post '/execute/?:action?' do |action|
ts = Time.now.utc.iso8601
payload = {
'x_account_id' => fields['x_account_id'],
Expand All @@ -59,25 +87,34 @@ def sign(fields, key=@key)
'x_result' => action,
'x_gateway_reference' => SecureRandom.hex,
'x_timestamp' => ts
}
}
%w(x_transaction_type x_message x_result).each do |field|
payload[field] = fields[field] if fields[field]
end

if action == "failed"
payload['x_message'] = "This is a custom error message."
end
payload['x_signature'] = sign(payload)
result = {timestamp: ts}
redirect_url = Addressable::URI.parse(fields['x_url_complete'])
redirect_url.query_values = payload
redirect_url = if fields['x_url_complete']
uri = Addressable::URI.parse(fields['x_url_complete'])
uri.query_values = payload
uri
end

if request.params['fire_callback'] == 'true'
callback_url = fields['x_url_callback']
response = HTTParty.post(callback_url, body: payload)
if response.code == 200
result[:redirect] = redirect_url
result[:redirect] = redirect_url if redirect_url
else
result[:error] = response
end
else
result[:redirect] = redirect_url
result[:redirect] = redirect_url if redirect_url
end
result.to_json
end

run! if app_file == $0

end
3 changes: 3 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test:
override:
- bundle exec ruby test/app_test.rb
25 changes: 25 additions & 0 deletions dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: hosted-payment-sim

up:
- homebrew:
- openssl
- ruby: 2.5.3
- railgun
- bundler

commands:
console:
syntax: ''
desc: 'open a console with the app loaded'
run: bundle exec irb -r ./app.rb
server:
syntax: ''
desc: 'start a rack server'
run: bundle exec rackup -o 192.168.64.1 -p 20000
test:
syntax: ''
desc: 'run app tests'
run: bundle exec ruby test/app_test.rb

open:
'Hosted Payment Simulator': https://hosted-payment-sim.myshopify.io
Binary file added offsite-gateway-sim-page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/dev-kit-screenshot.png
Binary file not shown.
6 changes: 5 additions & 1 deletion public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ code {
}
table.pure-table th, table.pure-table td {
padding: 3px 5px 3px 5px;
}
}

.pure-form-aligned .pure-control-group label {
width: 15em;
}
17 changes: 17 additions & 0 deletions railgun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://dev-accel.shopify.io/dev/railgun/Railgun-Config
name: hosted-payment-sim

vm:
image: /opt/dev/misc/railgun-images/default
ip_address: 192.168.64.37
memory: 2G
cores: 2

volumes:
root: 2G

services:
- nginx

hostnames:
- hosted-payment-sim.myshopify.io: { proxy_to_host_port: 20000 }
Loading