Skip to content

Commit

Permalink
Conekta: Add void action
Browse files Browse the repository at this point in the history
Closes #2245
  • Loading branch information
Mauricio Murga authored and davidsantoso committed Nov 3, 2016
1 parent 67ce67c commit 41734e5
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* Barclaycard SmartPay: Update supported countries [shasum]
* Worldpay: Report error code [curiousepic]
* CitrusPay: Update URL to current API version [davidsantoso]
* Conekta: Add void action [MauricioMurga]

== Version 1.60.0 (July 4, 2016)
* Orbital: Fix CC num leak on profile calls [drewblas]
Expand Down
7 changes: 6 additions & 1 deletion lib/active_merchant/billing/gateways/conekta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ConektaGateway < Gateway

def initialize(options = {})
requires!(options, :key)
options[:version] ||= '0.3.0'
options[:version] ||= '1.0.0'
super
end

Expand Down Expand Up @@ -55,6 +55,11 @@ def refund(money, identifier, options)
commit(:post, "charges/#{identifier}/refund", post)
end

def void(identifier, options = {})
post = {}
commit(:post, "charges/#{identifier}/void", post)
end

def supports_scrubbing
true
end
Expand Down
24 changes: 24 additions & 0 deletions test/remote/gateways/remote_conekta_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ def test_successful_refund
assert_equal nil, response.message
end

def test_successful_void
assert response = @gateway.authorize(@amount, @credit_card, @options)
assert_success response
assert_equal nil, response.message

identifier = response.params["id"]

assert response = @gateway.void(identifier)
assert_success response
assert_equal nil, response.message
end

def test_unsuccessful_void
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_success response
assert_equal nil, response.message

identifier = response.params["id"]

assert response = @gateway.void(identifier)
assert_failure response
assert_equal "El cargo no existe o no es apto para esta operación.", response.message
end

def test_unsuccessful_refund
assert response = @gateway.refund(@amount, "1", @options)
assert_failure response
Expand Down
89 changes: 89 additions & 0 deletions test/unit/gateways/conekta_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,36 @@ def test_successful_authorize
assert response.test?
end

def test_successful_void
@gateway.expects(:ssl_request).returns(successful_authorize_response)
assert response = @gateway.authorize(@amount, @credit_card, @options)
assert_success response
assert_instance_of Response, response
assert_equal nil, response.message
assert response.test?

@gateway.expects(:ssl_request).returns(successful_void_response)
assert response = @gateway.void(successful_authorize_response['id'])
assert_success response
assert_instance_of Response, response
assert_equal nil, response.message
assert response.test?
end

def test_unsuccessful_void
@gateway.expects(:ssl_request).returns(successful_authorize_response)
assert response = @gateway.authorize(@amount, @credit_card, @options)
assert_success response
assert_instance_of Response, response
assert_equal nil, response.message
assert response.test?

@gateway.expects(:ssl_request).returns(failed_void_response)
assert response = @gateway.void(successful_authorize_response['id'])
assert_failure response
assert response.test?
end

def test_unsuccessful_authorize
@gateway.expects(:ssl_request).returns(failed_authorize_response)
assert response = @gateway.authorize(@amount, @declined_card, @options)
Expand Down Expand Up @@ -259,6 +289,65 @@ def successful_authorize_response
}.to_json
end

def successful_void_response
{
'id' => '521b859fcfc26c0f180002d9',
'livemode' => false,
'created_at' => 1377535391,
'status' => 'voided',
'currency' => 'MXN',
'description' => 'Blue clip',
'reference_id' => nil,
'failure_code' => nil,
'failure_message' => nil,
'object' => 'charge',
'amount' => 300,
'processed_at' => nil,
'fee' => 348,
'card' => {
'name' => 'Mario Reyes',
'exp_month' => '01',
'exp_year' => '18',
'street2' => 'Paris',
'street3' => 'nil',
'city' => 'Guerrero',
'zip' => '5555',
'country' => 'Mexico',
'brand' => 'VISA',
'last4' => '1111',
'object' => 'card',
'fraud_response' => '3d_secure_required',
'redirect_form' => {
'url' => 'https => //eps.banorte.com/secure3d/Solucion3DSecure.htm',
'action' => 'POST',
'attributes' => {
'MerchantId' => '7376961',
'MerchantName' => 'GRUPO CONEKTAME',
'MerchantCity' => 'EstadodeMexico',
'Cert3D' => '03',
'ClientId' => '60518',
'Name' => '7376962',
'Password' => 'fgt563j',
'TransType' => 'PreAuth',
'Mode' => 'Y',
'E1' => 'qKNKjndV9emCxuKE1G4z',
'E2' => '521b859fcfc26c0f180002d9',
'E3' => 'Y',
'ResponsePath' => 'https => //eps.banorte.com/RespuestaCC.jsp',
'CardType' => 'VISA',
'Card' => '4111111111111111',
'Cvv2Indicator' => '1',
'Cvv2Val' => '183',
'Expires' => '01/18',
'Total' => '3.0',
'ForwardPath' => 'http => //localhost => 3000/charges/banorte_3d_secure_response',
'auth_token' => 'qKNKjndV9emCxuKE1G4z'
}
}
}
}.to_json
end

def failed_authorize_response
{
'message' => 'The card was declined',
Expand Down

0 comments on commit 41734e5

Please sign in to comment.