forked from activemerchant/active_merchant
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EwayManagedGateway#purchase now sends only expected fields and can se…
…t invoiceReference (from options[:order_id] or options[:invoice]) and invoiceDescription (from options[:description])
- Loading branch information
Showing
2 changed files
with
107 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,8 @@ def setup | |
:email => '[email protected]', | ||
:order_id => '1000', | ||
:customer => 'mycustomerref', | ||
:description => 'My Description' | ||
:description => 'My Description', | ||
:invoice => 'invoice-4567' | ||
} | ||
end | ||
|
||
|
@@ -80,6 +81,51 @@ def test_successful_purchase | |
assert_equal "123456", response.authorization | ||
assert response.test? | ||
end | ||
|
||
def test_expected_request_on_purchase | ||
@gateway.expects(:ssl_post).with { |endpoint, data, headers| | ||
# Compare the actual and expected XML documents, by converting them to Hashes first | ||
expected = Hash.from_xml(expected_purchase_request) | ||
actual = Hash.from_xml(data) | ||
expected == actual | ||
}.returns(successful_purchase_response) | ||
@gateway.purchase(@amount, @valid_customer_id, @options) | ||
end | ||
|
||
def test_purchase_invoice_reference_comes_from_order_id_or_invoice | ||
options = @options.dup | ||
|
||
# invoiceReference == options[:order_id] | ||
options[:order_id] = 'order_id' | ||
options.delete(:invoice) | ||
|
||
@gateway.expects(:ssl_post).with { |endpoint, data, headers| | ||
request_hash = Hash.from_xml(data) | ||
request_hash['Envelope']['Body']['ProcessPayment']['invoiceReference'] == 'order_id' | ||
}.returns(successful_purchase_response) | ||
@gateway.purchase(@amount, @valid_customer_id, options) | ||
|
||
# invoiceReference == options[:invoice] | ||
options[:invoice] = 'invoice' | ||
options.delete(:order_id) | ||
|
||
@gateway.expects(:ssl_post).with { |endpoint, data, headers| | ||
request_hash = Hash.from_xml(data) | ||
request_hash['Envelope']['Body']['ProcessPayment']['invoiceReference'] == 'invoice' | ||
}.returns(successful_purchase_response) | ||
@gateway.purchase(@amount, @valid_customer_id, options) | ||
|
||
# invoiceReference == options[:order_id] || options[:invoice] | ||
options[:order_id] = 'order_id' | ||
options[:invoice] = 'invoice' | ||
|
||
@gateway.expects(:ssl_post).with { |endpoint, data, headers| | ||
request_hash = Hash.from_xml(data) | ||
request_hash['Envelope']['Body']['ProcessPayment']['invoiceReference'] == 'order_id' | ||
}.returns(successful_purchase_response) | ||
@gateway.purchase(@amount, @valid_customer_id, options) | ||
|
||
end | ||
|
||
def test_invalid_customer_id | ||
@gateway.expects(:ssl_post).returns(unsuccessful_authorization_response) | ||
|
@@ -286,4 +332,28 @@ def expected_store_request | |
XML | ||
end | ||
|
||
# Documented here: https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?op=CreateCustomer | ||
def expected_purchase_request | ||
<<-XML | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> | ||
<soap12:Header> | ||
<eWAYHeader xmlns="https://www.eway.com.au/gateway/managedpayment"> | ||
<eWAYCustomerID>login</eWAYCustomerID> | ||
<Username>username</Username> | ||
<Password>password</Password> | ||
</eWAYHeader> | ||
</soap12:Header> | ||
<soap12:Body> | ||
<ProcessPayment xmlns="https://www.eway.com.au/gateway/managedpayment"> | ||
<managedCustomerID>#{@valid_customer_id}</managedCustomerID> | ||
<amount>#{@amount}</amount> | ||
<invoiceReference>#{@options[:order_id] || @options[:invoice]}</invoiceReference> | ||
<invoiceDescription>#{@options[:description]}</invoiceDescription> | ||
</ProcessPayment> | ||
</soap12:Body> | ||
</soap12:Envelope> | ||
XML | ||
end | ||
|
||
end |