This repository has been archived by the owner on May 27, 2021. It is now read-only.
forked from activemerchant/active_merchant
-
Notifications
You must be signed in to change notification settings - Fork 2
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 activemerchant#920 from Shopify/payu_checksum
Payu(Paisa) refactor
- Loading branch information
Showing
16 changed files
with
96 additions
and
104 deletions.
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
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
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
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ class RemotePayuInIntegrationTest < Test::Unit::TestCase | |
include ActiveMerchant::Billing::Integrations | ||
|
||
def setup | ||
@payu_in = PayuIn::Notification.new(http_raw_data, :credential1 => 'C0Dr8m', :credential2 => '3sf0jURk') | ||
@payu_in = PayuIn::Notification.new(http_raw_data, :credential1 => 'merchant_id', :credential2 => 'secret') | ||
end | ||
|
||
def test_raw | ||
|
@@ -21,6 +21,6 @@ def test_raw | |
|
||
private | ||
def http_raw_data | ||
"mihpayid=403993715508030204&mode=CC&status=success&unmappedstatus=captured&key=C0Dr8m&txnid=4ba4afe87f7e73468f2a&amount=10.00&discount=0.00&addedon=2013-05-10 18 32 30&productinfo=Product Info&firstname=Payu-Admin&lastname=&address1=&address2=&city=&state=&country=&zipcode=&[email protected]&phone=1234567890&udf1=&udf2=&udf3=&udf4=&udf5=&udf6=&udf7=&udf8=&udf9=&udf10=&hash=ef0c1b509a42b802a4938c25dc9bb9efe40b75a7dfb8bde1a6f126fa1f86cee264c5e5a17e87db85150d6d8912eafda838416e669712f1989dcb9cbdb8c24219&field1=313069903923&field2=999999&field3=59117331831301&field4=-1&field5=&field6=&field7=&field8=&PG_TYPE=HDFC&bank_ref_num=59117331831301&bankcode=CC&error=E000&cardnum=512345XXXXXX2346&cardhash=766f0227cc4b4c5f773a04cb31d8d1c5be071dd8d08fe365ecf5e2e5c947546d" | ||
"mihpayid=403993715508030204&mode=CC&status=success&unmappedstatus=captured&key=merchant_id&txnid=4ba4afe87f7e73468f2a&amount=10.00&discount=0.00&addedon=2013-05-10 18 32 30&productinfo=Product Info&firstname=Payu-Admin&lastname=&address1=&address2=&city=&state=&country=&zipcode=&[email protected]&phone=1234567890&udf1=&udf2=&udf3=&udf4=&udf5=&udf6=&udf7=&udf8=&udf9=&udf10=&hash=ef0c1b509a42b802a4938c25dc9bb9efe40b75a7dfb8bde1a6f126fa1f86cee264c5e5a17e87db85150d6d8912eafda838416e669712f1989dcb9cbdb8c24219&field1=313069903923&field2=999999&field3=59117331831301&field4=-1&field5=&field6=&field7=&field8=&PG_TYPE=HDFC&bank_ref_num=59117331831301&bankcode=CC&error=E000&cardnum=512345XXXXXX2346&cardhash=766f0227cc4b4c5f773a04cb31d8d1c5be071dd8d08fe365ecf5e2e5c947546d" | ||
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 |
---|---|---|
|
@@ -4,14 +4,13 @@ class PayuInHelperTest < Test::Unit::TestCase | |
include ActiveMerchant::Billing::Integrations | ||
|
||
def setup | ||
@helper = PayuIn::Helper.new( 'jh34h53kj4h5hj34kh5', 'C0Dr8m', :amount => '10.00', :credential2 => 'Product Info') | ||
@helper = PayuIn::Helper.new( 'order_id', 'merchant_id', :amount => '10.00', :credential2 => 'secret_key') | ||
end | ||
|
||
def test_basic_helper_fields | ||
assert_equal '10.00', @helper.fields['amount'] | ||
assert_equal 'C0Dr8m', @helper.fields['key'] | ||
assert_equal 'jh34h53kj4h5hj34kh5', @helper.fields['txnid'] | ||
assert_equal 'Product Info', @helper.fields['productinfo'] | ||
assert_equal 'merchant_id', @helper.fields['key'] | ||
assert_equal 'order_id', @helper.fields['txnid'] | ||
end | ||
|
||
def test_customer_fields | ||
|
@@ -56,11 +55,20 @@ def test_user_defined_fields | |
end | ||
|
||
def test_add_checksum_method | ||
options = { :mode => 'CC' } | ||
@helper.customer :first_name => 'Payu-Admin', :email => '[email protected]' | ||
@helper.description "Product Info" | ||
@helper.user_defined :var1 => 'var_one', :var2 => 'var_two', :var3 => 'var_three', :var4 => 'var_four', :var5 => 'var_five', :var6 => 'var_six', :var7 => 'var_seven', :var8 => 'var_eight', :var9 => 'var_nine', :var10 => 'var_ten' | ||
|
||
assert_equal "032606d7fb5cfe357d9e6b358b4bb8db1d34e9dfa30f039cb7dec75ae6d77f7d1f67a58c123ea0ee358bf040554d5e3048066a369ae63888132e27c14e79ee5a", @helper.form_fields["hash"] | ||
fields = ["txnid", "amount", "productinfo", "firstname", "email", "udf1", "udf2", "udf3", "udf4", "udf5", "udf6", "udf7", "udf8", "udf9", "udf10"].map { |field| @helper.fields[field] } | ||
assert_equal Digest::SHA512.hexdigest(['merchant_id', *fields, 'secret_key'].join("|")), @helper.form_fields["hash"] | ||
end | ||
|
||
def test_sanitize_fields_in_form_fields | ||
@helper.description '{[Valid Description!]}' | ||
@helper.form_fields | ||
|
||
assert_equal 'Valid Description', @helper.fields['productinfo'] | ||
assert_nil @helper.fields['email'] | ||
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 |
---|---|---|
|
@@ -4,14 +4,13 @@ class PayuInPaisaHelperTest < Test::Unit::TestCase | |
include ActiveMerchant::Billing::Integrations | ||
|
||
def setup | ||
@helper = PayuInPaisa::Helper.new( 'jh34h53kj4h5hj34kh5', 'C0Dr8m', :amount => '10.00', :credential2 => 'Product Info') | ||
@helper = PayuInPaisa::Helper.new( 'order_id', 'merchant_id', :amount => '10.00', :credential2 => 'secret') | ||
end | ||
|
||
def test_basic_helper_fields | ||
assert_equal '10.00', @helper.fields['amount'] | ||
assert_equal 'C0Dr8m', @helper.fields['key'] | ||
assert_equal 'jh34h53kj4h5hj34kh5', @helper.fields['txnid'] | ||
assert_equal 'Product Info', @helper.fields['productinfo'] | ||
assert_equal 'merchant_id', @helper.fields['key'] | ||
assert_equal 'order_id', @helper.fields['txnid'] | ||
end | ||
|
||
def test_customer_fields | ||
|
@@ -56,10 +55,12 @@ def test_user_defined_fields | |
end | ||
|
||
def test_add_checksum_method | ||
options = { :mode => 'CC' } | ||
@helper.customer :first_name => 'Payu-Admin', :email => '[email protected]' | ||
@helper.user_defined :var1 => 'var_one', :var2 => 'var_two', :var3 => 'var_three', :var4 => 'var_four', :var5 => 'var_five', :var6 => 'var_six', :var7 => 'var_seven', :var8 => 'var_eight', :var9 => 'var_nine', :var10 => 'var_ten' | ||
@helper.description 'Product Info' | ||
|
||
assert_equal "032606d7fb5cfe357d9e6b358b4bb8db1d34e9dfa30f039cb7dec75ae6d77f7d1f67a58c123ea0ee358bf040554d5e3048066a369ae63888132e27c14e79ee5a", @helper.form_fields["hash"] | ||
payload = 'merchant_id|order_id|10.00|Product Info|Payu-Admin|[email protected]|var_one|var_two|var_three|var_four|var_five|var_six|var_seven|var_eight|var_nine|var_ten|secret' | ||
checksum = Digest::SHA512.hexdigest(payload) | ||
assert_equal checksum, @helper.form_fields["hash"] | ||
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ class PayuInNotificationTest < Test::Unit::TestCase | |
include ActiveMerchant::Billing::Integrations | ||
|
||
def setup | ||
@payu = PayuIn::Notification.new(http_raw_data, :credential1 => 'C0Dr8m', :credential2 => '3sf0jURk') | ||
@payu = PayuIn::Notification.new(http_raw_data, :credential1 => 'merchant_id', :credential2 => 'secret') | ||
end | ||
|
||
def test_accessors | ||
|
@@ -19,13 +19,13 @@ def test_accessors | |
assert_equal true, @payu.amount_ok?(BigDecimal.new('10.00'),BigDecimal.new('0.00')) | ||
assert_equal "CC", @payu.type | ||
assert_equal "4ba4afe87f7e73468f2a", @payu.invoice | ||
assert_equal "C0Dr8m", @payu.account | ||
assert_equal "merchant_id", @payu.account | ||
assert_equal "0.00", @payu.discount | ||
assert_equal "[email protected]", @payu.customer_email | ||
assert_equal "1234567890", @payu.customer_phone | ||
assert_equal "Payu-Admin", @payu.customer_first_name | ||
assert_equal "", @payu.customer_last_name | ||
assert_equal "ef0c1b509a42b802a4938c25dc9bb9efe40b75a7dfb8bde1a6f126fa1f86cee264c5e5a17e87db85150d6d8912eafda838416e669712f1989dcb9cbdb8c24219", @payu.checksum | ||
assert_equal "d6a5544072d036dc422d1c6393a8da75233d5e30ffc848f11682f121d67cd80c0d4fed1067b99918b5a377b7dcf1c8c9c79975abdf9f444692b35bf34d494105", @payu.checksum | ||
assert_equal "E000", @payu.message | ||
assert_equal true, @payu.checksum_ok? | ||
end | ||
|
@@ -38,12 +38,8 @@ def test_acknowledgement | |
assert @payu.acknowledge | ||
end | ||
|
||
def test_respond_to_acknowledge | ||
assert @payu.respond_to?(:acknowledge) | ||
end | ||
|
||
private | ||
def http_raw_data | ||
"mihpayid=403993715508030204&mode=CC&status=success&unmappedstatus=captured&key=C0Dr8m&txnid=4ba4afe87f7e73468f2a&amount=10.00&discount=0.00&addedon=2013-05-10 18 32 30&productinfo=Product Info&firstname=Payu-Admin&lastname=&address1=&address2=&city=&state=&country=&zipcode=&[email protected]&phone=1234567890&udf1=&udf2=&udf3=&udf4=&udf5=&udf6=&udf7=&udf8=&udf9=&udf10=&hash=ef0c1b509a42b802a4938c25dc9bb9efe40b75a7dfb8bde1a6f126fa1f86cee264c5e5a17e87db85150d6d8912eafda838416e669712f1989dcb9cbdb8c24219&field1=313069903923&field2=999999&field3=59117331831301&field4=-1&field5=&field6=&field7=&field8=&PG_TYPE=HDFC&bank_ref_num=59117331831301&bankcode=CC&error=E000&cardnum=512345XXXXXX2346&cardhash=766f0227cc4b4c5f773a04cb31d8d1c5be071dd8d08fe365ecf5e2e5c947546d" | ||
"mihpayid=403993715508030204&mode=CC&status=success&unmappedstatus=captured&key=merchant_id&txnid=4ba4afe87f7e73468f2a&amount=10.00&discount=0.00&addedon=2013-05-10 18 32 30&productinfo=Product Info&firstname=Payu-Admin&lastname=&address1=&address2=&city=&state=&country=&zipcode=&[email protected]&phone=1234567890&udf1=&udf2=&udf3=&udf4=&udf5=&udf6=&udf7=&udf8=&udf9=&udf10=&hash=d6a5544072d036dc422d1c6393a8da75233d5e30ffc848f11682f121d67cd80c0d4fed1067b99918b5a377b7dcf1c8c9c79975abdf9f444692b35bf34d494105&field1=313069903923&field2=999999&field3=59117331831301&field4=-1&field5=&field6=&field7=&field8=&PG_TYPE=HDFC&bank_ref_num=59117331831301&bankcode=CC&error=E000&cardnum=512345XXXXXX2346&cardhash=766f0227cc4b4c5f773a04cb31d8d1c5be071dd8d08fe365ecf5e2e5c947546d" | ||
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ class PayuInPaisaNotificationTest < Test::Unit::TestCase | |
include ActiveMerchant::Billing::Integrations | ||
|
||
def setup | ||
@payu = PayuInPaisa::Notification.new(http_raw_data, :credential1 => 'C0Dr8m', :credential2 => '3sf0jURk') | ||
@payu = PayuInPaisa::Notification.new(http_raw_data, :credential1 => 'merchant_id', :credential2 => 'secret') | ||
end | ||
|
||
def test_accessors | ||
|
@@ -19,13 +19,13 @@ def test_accessors | |
assert_equal true, @payu.amount_ok?(BigDecimal.new('10.00'),BigDecimal.new('0.00')) | ||
assert_equal "CC", @payu.type | ||
assert_equal "4ba4afe87f7e73468f2a", @payu.invoice | ||
assert_equal "C0Dr8m", @payu.account | ||
assert_equal "merchant_id", @payu.account | ||
assert_equal "0.00", @payu.discount | ||
assert_equal "[email protected]", @payu.customer_email | ||
assert_equal "1234567890", @payu.customer_phone | ||
assert_equal "Payu-Admin", @payu.customer_first_name | ||
assert_equal "", @payu.customer_last_name | ||
assert_equal "e35f67dc7232d12caa28b16ba31b509f62bdea1e930bb6766a4f71036cc1af34debb8afc0fdd89be50f0604c1e6bca7209dfffe6b3a893c575492edcab3444ee", @payu.checksum | ||
assert_equal checksum, @payu.checksum | ||
assert_equal "E000", @payu.message | ||
assert_equal true, @payu.checksum_ok? | ||
end | ||
|
@@ -38,16 +38,16 @@ def test_acknowledgement | |
assert @payu.acknowledge | ||
end | ||
|
||
def test_respond_to_acknowledge | ||
assert @payu.respond_to?(:acknowledge) | ||
end | ||
|
||
def test_item_id_gives_the_original_item_id | ||
assert 'original_item_id', @payu.item_id | ||
end | ||
|
||
private | ||
def http_raw_data | ||
"mihpayid=403993715508030204&mode=CC&status=success&unmappedstatus=captured&key=C0Dr8m&txnid=4ba4afe87f7e73468f2a&amount=10.00&discount=0.00&addedon=2013-05-10 18 32 30&productinfo=Product Info&firstname=Payu-Admin&lastname=&address1=&address2=&city=&state=&country=&zipcode=&[email protected]&phone=1234567890&udf1=&udf2=original_item_id&udf3=&udf4=&udf5=&udf6=&udf7=&udf8=&udf9=&udf10=&hash=e35f67dc7232d12caa28b16ba31b509f62bdea1e930bb6766a4f71036cc1af34debb8afc0fdd89be50f0604c1e6bca7209dfffe6b3a893c575492edcab3444ee&field1=313069903923&field2=999999&field3=59117331831301&field4=-1&field5=&field6=&field7=&field8=&PG_TYPE=HDFC&bank_ref_num=59117331831301&bankcode=CC&error=E000&cardnum=512345XXXXXX2346&cardhash=766f0227cc4b4c5f773a04cb31d8d1c5be071dd8d08fe365ecf5e2e5c947546d" | ||
"mihpayid=403993715508030204&mode=CC&status=success&unmappedstatus=captured&key=merchant_id&txnid=4ba4afe87f7e73468f2a&amount=10.00&discount=0.00&addedon=2013-05-10 18 32 30&productinfo=Product Info&firstname=Payu-Admin&lastname=&address1=&address2=&city=&state=&country=&zipcode=&[email protected]&phone=1234567890&udf1=&udf2=original_item_id&udf3=&udf4=&udf5=&udf6=&udf7=&udf8=&udf9=&udf10=&hash=#{checksum}&field1=313069903923&field2=999999&field3=59117331831301&field4=-1&field5=&field6=&field7=&field8=&PG_TYPE=HDFC&bank_ref_num=59117331831301&bankcode=CC&error=E000&cardnum=512345XXXXXX2346&cardhash=766f0227cc4b4c5f773a04cb31d8d1c5be071dd8d08fe365ecf5e2e5c947546d" | ||
end | ||
|
||
def checksum | ||
Digest::SHA512.hexdigest("secret|success|||||||||original_item_id||[email protected]|Payu-Admin|Product Info|10.00|4ba4afe87f7e73468f2a|merchant_id") | ||
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 |
---|---|---|
|
@@ -5,8 +5,8 @@ class PayuInModuleTest < Test::Unit::TestCase | |
|
||
def setup | ||
ActiveMerchant::Billing::Base.integration_mode = :test | ||
@merchant_id = 'C0Dr8m' | ||
@secret_key = '3sf0jURk' | ||
@merchant_id = 'merchant_id' | ||
@secret_key = 'secret' | ||
end | ||
|
||
def test_service_url_method | ||
|
@@ -26,7 +26,8 @@ def test_notification_method | |
end | ||
|
||
def test_checksum_method | ||
payu_load = "4ba4afe87f7e73468f2a|10.00|Product Info|Payu-Admin|[email protected]||||||||||" | ||
assert_equal "cd324f64891b07d95492a2fd80ae469092e302faa3d3df5ba1b829936fd7497b6e89c3e48fd70e2a131cdd4f17d14bc20f292e9408650c085bc3bedb32f44266", PayuIn.checksum(@merchant_id, @secret_key, payu_load) | ||
payu_load = "order_id|10.00|Product Info|Payu-Admin|[email protected]||||||||||" | ||
checksum = Digest::SHA512.hexdigest([@merchant_id, payu_load, @secret_key].join("|")) | ||
assert_equal checksum, PayuIn.checksum(@merchant_id, @secret_key, payu_load.split("|", -1)) | ||
end | ||
end |
Oops, something went wrong.