Skip to content

Commit

Permalink
Merge pull request #23 from compropago/staging
Browse files Browse the repository at this point in the history
fix bug and add contract
  • Loading branch information
danteay authored Feb 13, 2017
2 parents 88d303e + 3af0c95 commit f3d5a42
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Gemfile.lock
.idea
releases/
*.gem
17 changes: 15 additions & 2 deletions Rakefile
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

2 changes: 1 addition & 1 deletion compropago_sdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Dir.glob('./lib/compropago_sdk/tools/*.rb').each do |archivo| li.push archivo en

Gem::Specification.new do |spec|
spec.name = 'compropago_sdk'
spec.version = '3.0.3'
spec.version = '3.0.4'
spec.authors = ['Eduardo Aguilar']
spec.email = ['eduardo.aguilar@compropago.com']

Expand Down
1 change: 1 addition & 0 deletions lib/compropago_sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
require 'compropago_sdk/factory/models/instructions'
require 'compropago_sdk/factory/models/new_order_info'
require 'compropago_sdk/factory/models/order_info'
require 'compropago_sdk/factory/models/exchange'
require 'compropago_sdk/factory/models/place_order_info'
require 'compropago_sdk/factory/models/provider'
require 'compropago_sdk/factory/models/sms_data'
Expand Down
2 changes: 1 addition & 1 deletion lib/compropago_sdk/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Client
API_LIVE_URI = 'https://api.compropago.com/v1/'
API_SANDBOX_URI = 'https://api.compropago.com/v1/'

VERSION = '3.0.3'
VERSION = '3.0.4'

attr_accessor :publickey, :privatekey, :live, :deploy_uri, :api

Expand Down
11 changes: 11 additions & 0 deletions lib/compropago_sdk/factory/models/exchange.rb
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
5 changes: 2 additions & 3 deletions lib/compropago_sdk/factory/models/fee_details.rb
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
8 changes: 4 additions & 4 deletions lib/compropago_sdk/factory/models/instruction_details.rb
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
1 change: 1 addition & 0 deletions lib/compropago_sdk/factory/models/new_order_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class NewOrderInfo
attr_accessor :order_info
attr_accessor :fee_details
attr_accessor :instructions
attr_accessor :api_version

def initialize
@order_info = OrderInfo.new
Expand Down
10 changes: 5 additions & 5 deletions lib/compropago_sdk/factory/models/order_info.rb
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
43 changes: 29 additions & 14 deletions lib/compropago_sdk/factory/serialize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def self.cp_order_info(data=nil)

obj.fee_details = Serialize::fee_details(data['fee_details'])
obj.order_info = Serialize::order_info(data['order_info'])
obj.customer.customer_name = Serialize::customer(data['customer'])
obj.customer = Serialize::customer(data['customer'])

obj.captured = data['captured']
obj.failure_message = data['failure_message']
Expand Down Expand Up @@ -89,13 +89,12 @@ def self.fee_details(data=nil)
obj = FeeDetails.new

obj.amount = data['amount'] ? data['amount'] : nil
obj.tax = data['tax'] ? data['tax'] : nil
obj.tax_percent = data['tax_percent'] ? data['tax_percent'] : nil
obj.currency = data['currency'] ? data['currency'] : nil
obj.type = data['type'] ? data['type'] : nil
obj.description = data['description'] ? data['description'] : nil
obj.application = data['application'] ? data['application'] : nil
obj.tax_percent = data['tax_percent'] ? data['tax_percent'] : nil
obj.amount_refunded = data['amount_refunded'] ? data['amount_refunded'] : nil
obj.tax = data['tax'] ? data['tax'] : nil

return obj
end
Expand All @@ -107,17 +106,17 @@ def self.instruction_details(data=nil)
else
obj = InstructionDetails.new

obj.amount = data['amount'] ? data['amount'] : nil
obj.store = data['store'] ? data['store'] : nil
obj.payment_amount = data['payment_amount'] ? data['payment_amount'] : nil
obj.payment_store = data['payment_store'] ? data['payment_store'] : nil
obj.bank_account_holder_name = data['bank_account_holder_name'] ? data['bank_account_holder_name'] : nil
obj.bank_account_number = data['bank_accont_number'] ? data['bank_accont_number'] : nil
obj.bank_reference = data['bank_reference'] ? data['bank_reference'] : nil
obj.amount = data['amount'] ? data['amount'] : nil
obj.store = data['store'] ? data['store'] : nil
obj.bank_account_number = data['bank_account_number'] ? data['bank_account_number'] : nil
obj.company_reference_name = data['company_reference_name'] ? data['company_reference_name'] : nil
obj.company_reference_number = data['company_reference_number'] ? data['company_reference_number'] : nil
obj.company_bank_number = data['company_bank_number'] ? data['company_bank_number'] : nil
obj.order_reference_number = data['order_reference_number'] ? data['order_reference_number'] : nil
obj.bank_account_holder_name = data['bank_account_holder_name'] ? data['bank_account_holder_name'] : nil
obj.bank_reference = data['bank_reference'] ? data['bank_reference'] : nil
obj.bank_name = data['bank_name'] ? data['bank_name'] : nil

return obj
Expand Down Expand Up @@ -160,6 +159,7 @@ def self.new_order_info(data=nil)
obj.order_info = Serialize::order_info(data['order_info'])
obj.fee_details = Serialize::fee_details(data['fee_details'])
obj.instructions = Serialize::instructions(data['instructions'])
obj.api_version = data['api_version']

return obj
end
Expand All @@ -172,13 +172,28 @@ def self.order_info(data=nil)
obj = OrderInfo.new

obj.order_id = data['order_id'] ? data['order_id'] : nil
obj.order_price = data['order_price'] ? data['order_price'] : nil
obj.order_name = data['order_name'] ? data['order_name'] : nil
obj.payment_method = data['payment_method'] ? data['payment_method'] : nil
obj.store = data['store'] ? data['store'] : nil
obj.country = data['country'] ? data['country'] : nil
obj.order_price = data['order_price'] ? data['order_price'] : nil
obj.image_url = data['image_url'] ? data['image_url'] : nil
obj.success_url = data['success_url'] ? data['success_url'] : nil
obj.exchange = Serialize::exchange(data['exchange'])

return obj
end
end

def self.exchange(data=nil)
if data.nil?
return Exchange.new
else
obj = Exchange.new

obj.rate = data['rate'] ? data['rate'] : nil
obj.request = data['request'] ? data['request'] : nil
obj.origin_amount = data['origin_amount'] ? data['origin_amount'] : nil
obj.final_amount = data['final_amount'] ? data['final_amount'] : nil
obj.origin_currency = data['origin_currency'] ? data['origin_currency'] : nil
obj.final_currency = data['final_currency'] ? data['final_currency'] : nil
obj.exchange_id = data['exchange_id'] ? data['exchange_id'] : nil

return obj
end
Expand Down
87 changes: 87 additions & 0 deletions test/contract/neworder_test.rb
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
Loading

0 comments on commit f3d5a42

Please sign in to comment.