-
Notifications
You must be signed in to change notification settings - Fork 7
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 #23 from compropago/staging
fix bug and add contract
- Loading branch information
Showing
13 changed files
with
177 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
Gemfile.lock | ||
.idea | ||
releases/ | ||
*.gem |
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 |
---|---|---|
@@ -1,11 +1,24 @@ | ||
require 'bundler/gem_tasks' | ||
require 'rake/testtask' | ||
|
||
Rake::TestTask.new(:test) do |t| | ||
Rake::TestTask.new(:unit) do |t| | ||
t.libs << 'test' | ||
t.libs << 'lib' | ||
t.test_files = FileList['test/**/unit_test.rb'] | ||
end | ||
|
||
Rake::TestTask.new(:contract) do |t| | ||
t.libs << 'test' | ||
t.libs << 'lib' | ||
t.test_files = FileList['test/contract/**/*_test.rb'] | ||
end | ||
|
||
Rake::TestTask.new(:full) do |t| | ||
t.libs << 'test' | ||
t.libs << 'lib' | ||
t.test_files = FileList['test/**/*_test.rb'] | ||
end | ||
|
||
task :default => :test | ||
|
||
task :default => :full | ||
|
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Exchange | ||
|
||
attr_accessor :rate | ||
attr_accessor :request | ||
attr_accessor :origin_amount | ||
attr_accessor :final_amount | ||
attr_accessor :origin_currency | ||
attr_accessor :final_currency | ||
attr_accessor :exchange_id | ||
|
||
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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
class FeeDetails | ||
|
||
attr_accessor :amount | ||
attr_accessor :tax | ||
attr_accessor :tax_percent | ||
attr_accessor :currency | ||
attr_accessor :type | ||
attr_accessor :description | ||
attr_accessor :application | ||
attr_accessor :tax_percent | ||
attr_accessor :amount_refunded | ||
attr_accessor :tax | ||
|
||
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
class InstructionDetails | ||
|
||
attr_accessor :amount | ||
attr_accessor :store | ||
attr_accessor :payment_amount | ||
attr_accessor :payment_store | ||
attr_accessor :bank_account_holder_name | ||
attr_accessor :amount | ||
attr_accessor :store | ||
attr_accessor :bank_account_number | ||
attr_accessor :bank_reference | ||
attr_accessor :company_reference_name | ||
attr_accessor :company_reference_number | ||
attr_accessor :company_bank_number | ||
attr_accessor :order_reference_number | ||
attr_accessor :bank_account_holder_name | ||
attr_accessor :bank_reference | ||
attr_accessor :bank_name | ||
|
||
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
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
class OrderInfo | ||
|
||
attr_accessor :order_id | ||
attr_accessor :order_price | ||
attr_accessor :order_name | ||
attr_accessor :payment_method | ||
attr_accessor :store | ||
attr_accessor :country | ||
attr_accessor :order_price | ||
attr_accessor :image_url | ||
attr_accessor :success_url | ||
attr_accessor :exchange | ||
|
||
def initialize | ||
@exchange = Exchange.new | ||
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
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,87 @@ | ||
require 'minitest/autorun' | ||
|
||
# Importar el archivo principal de la gema (lib/scafold_gem) | ||
require 'compropago_sdk' | ||
|
||
class NeworderTest < MiniTest::Unit::TestCase | ||
|
||
def setup | ||
@client = Client.new('pk_live_760db54141134cbcb0', 'sk_live_6432b0141302941f8b', true) | ||
@order_info = { | ||
:order_id => 1232, | ||
:order_name => 'M4 Contract SDK ruby', | ||
:order_price => 123, | ||
:customer_name => 'Eduardo Aguilar Y', | ||
:customer_email => 'eduardo.aguilar@compropago.com', | ||
:payment_type => 'OXXO' | ||
} | ||
end | ||
|
||
def test_main | ||
res = false | ||
begin | ||
order = Factory::get_instance_of('PlaceOrderInfo', @order_info) | ||
new_order = @client.api.place_order(order) | ||
|
||
if (new_order.id =~ /^ch_([0-9a-z]*)-([0-9a-z]*)-([0-9a-z]*)-([0-9a-z]*)-([0-9a-z]*)$/) == nil | ||
raise 'Error: id == '+new_order.id | ||
end | ||
if (new_order.short_id =~ /^[0-9a-z]{6}$/) == nil | ||
raise 'Error: short_id == '+new_order.short_id | ||
end | ||
unless new_order.object == 'charge' | ||
raise 'Error: object == '+new_order.object | ||
end | ||
unless new_order.created.is_a? Numeric | ||
raise 'Error: created == '+new_order.created.class | ||
end | ||
unless new_order.exp_date.is_a? Numeric | ||
raise 'Error: exp_date == '+new_order.exp_date.class | ||
end | ||
unless new_order.status.is_a? String || new_order.status != 'pending' | ||
raise 'Error: status == '+new_order.status.class+'|'+new_order.status | ||
end | ||
unless !!new_order.live_mode == new_order.live_mode | ||
raise 'Error: live_mode == '+new_order.live_mode.class | ||
end | ||
if new_order.api_version != '1.0' && new_order.api_version != '1.1' | ||
raise 'Error: api_version == '+new_order.api_version | ||
end | ||
|
||
validate_order_info new_order.order_info | ||
|
||
res = true | ||
rescue => ex | ||
puts ex.message | ||
end | ||
|
||
assert res | ||
end | ||
|
||
def validate_order_info(order_info) | ||
if order_info.order_id == '' || order_info.order_id.nil? | ||
raise 'Error: order_info.order_id == '+order_info.order_id | ||
end | ||
if order_info.order_name == '' || order_info.order_name.nil? | ||
raise 'Error: order_info.order_name == '+order_info.order_name | ||
end | ||
if (order_info.order_price =~ /^[0-9]+(\.[0-9]+)*$/) == nil | ||
raise 'Error: order_info.order_price == '+order_info.order_price+'|'+order_info.order_price.class | ||
end | ||
|
||
validate_exchange order_info.exchange | ||
end | ||
|
||
def validate_exchange(exchange) | ||
unless exchange.origin_amount.is_a? Numeric | ||
raise 'Error: exchange.origin_amount == '+exchange.origin_amount.class | ||
end | ||
if exchange.origin_currency != 'MXN' && exchange.origin_currency != 'USD' && exchange.origin_currency != 'GBP' && exchange.origin_currency != 'EUR' | ||
raise 'Error: exchange.origin_currency == '+exchange.origin_currency | ||
end | ||
unless exchange.final_amount.is_a? Numeric | ||
raise 'Error: exchange.final_amount == '+exchange.final_amount | ||
end | ||
end | ||
|
||
end |
Oops, something went wrong.