-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from Shopify/add_yuupay
Adding Yuupay gateway as universal
- Loading branch information
Showing
3 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module OffsitePayments #:nodoc: | ||
module Integrations #:nodoc: | ||
module Yuupay | ||
include Universal | ||
class Helper < Universal::Helper | ||
def forward_url | ||
'https://checkout.yuupay.net/payment/index.php' | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
require 'test_helper' | ||
|
||
class YuupayHelperTest < Test::Unit::TestCase | ||
include OffsitePayments::Integrations | ||
|
||
def setup | ||
@order = 'order-500' | ||
@account = 'zork' | ||
@key = 'TO78ghHCfBQ6ZBw2Q2fJ3wRwGkWkUHVs' | ||
@amount = 123.45 | ||
@currency = 'USD' | ||
@test = false | ||
@country = 'US' | ||
@account_name = 'Widgets Inc' | ||
@transaction_type = 'sale' | ||
@options = {:amount => @amount, | ||
:currency => @currency, | ||
:test => @test, | ||
:credential2 => @key, | ||
:country => @country, | ||
:account_name => @account_name, | ||
:transaction_type => @transaction_type} | ||
@helper = Yuupay::Helper.new(@order, @account, @options) | ||
end | ||
|
||
def test_forward_url | ||
assert_equal @helper.forward_url, @helper.credential_based_url | ||
end | ||
|
||
def test_core_fields | ||
@helper.shipping 6.78 | ||
@helper.tax 0 | ||
@helper.description 'Box of Red Wine' | ||
@helper.invoice 'Invoice #1A' | ||
|
||
assert_field 'x_account_id', @account | ||
assert_field 'x_currency', @currency | ||
assert_field 'x_amount', '123.45' | ||
assert_field 'x_amount_shipping', '6.78' | ||
assert_field 'x_amount_tax', '0.00' | ||
assert_field 'x_reference', @order | ||
assert_field 'x_shop_country', @country | ||
assert_field 'x_shop_name', @account_name | ||
assert_field 'x_transaction_type', @transaction_type | ||
assert_field 'x_description', 'Box of Red Wine' | ||
assert_field 'x_invoice', 'Invoice #1A' | ||
assert_field 'x_test', @test.to_s | ||
end | ||
|
||
def test_special_currency_formatting | ||
@options[:currency] = 'COU' | ||
@helper = Universal::Helper.new(@order, @account, @options) | ||
@helper.shipping 6.78 | ||
@helper.tax 0 | ||
|
||
assert_field 'x_currency', 'COU' | ||
assert_field 'x_amount', '123.4500' | ||
assert_field 'x_amount_shipping', '6.7800' | ||
assert_field 'x_amount_tax', '0.0000' | ||
end | ||
|
||
def test_customer_fields | ||
@helper.customer :first_name => 'Cody', | ||
:last_name => 'Fauser', | ||
:email => '[email protected]', | ||
:phone => '(613) 456-7890' | ||
|
||
assert_field 'x_customer_first_name', 'Cody' | ||
assert_field 'x_customer_last_name', 'Fauser' | ||
assert_field 'x_customer_email', '[email protected]' | ||
assert_field 'x_customer_phone', '(613) 456-7890' | ||
end | ||
|
||
def test_shipping_address_fields | ||
@helper.shipping_address :first_name => 'John', | ||
:last_name => 'Doe', | ||
:city => 'Toronto', | ||
:company => 'Shopify Toronto', | ||
:address1 => '241 Spadina Ave', | ||
:address2 => 'Front Entrance', | ||
:state => 'ON', | ||
:zip => 'M5T 3A8', | ||
:country => 'CA', | ||
:phone => '(416) 123-4567' | ||
|
||
assert_field 'x_customer_shipping_first_name', 'John' | ||
assert_field 'x_customer_shipping_last_name', 'Doe' | ||
assert_field 'x_customer_shipping_city', 'Toronto' | ||
assert_field 'x_customer_shipping_company', 'Shopify Toronto' | ||
assert_field 'x_customer_shipping_address1', '241 Spadina Ave' | ||
assert_field 'x_customer_shipping_address2', 'Front Entrance' | ||
assert_field 'x_customer_shipping_state', 'ON' | ||
assert_field 'x_customer_shipping_zip', 'M5T 3A8' | ||
assert_field 'x_customer_shipping_country', 'CA' | ||
assert_field 'x_customer_shipping_phone', '(416) 123-4567' | ||
end | ||
|
||
def test_url_fields | ||
@helper.notify_url 'https://zork.com/notify' | ||
@helper.return_url 'https://zork.com/return' | ||
@helper.cancel_return_url 'https://zork.com/cancel' | ||
|
||
assert_field 'x_url_callback', 'https://zork.com/notify' | ||
assert_field 'x_url_complete', 'https://zork.com/return' | ||
assert_field 'x_url_cancel', 'https://zork.com/cancel' | ||
end | ||
|
||
def test_signature | ||
expected_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, @key, 'x_account_idzorkx_amount123.45x_currencyUSDx_referenceorder-500x_shop_countryUSx_shop_nameWidgets Incx_testfalsex_transaction_typesale') | ||
@helper.sign_fields | ||
|
||
assert_field 'x_signature', expected_signature | ||
end | ||
end |