Skip to content

Commit

Permalink
USA ePay Advanced: Add quick_update_customer action
Browse files Browse the repository at this point in the history
Closes #2229
  • Loading branch information
joshreeves authored and davidsantoso committed Mar 6, 2017
1 parent 8d09027 commit c063a49
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Kushki: Remove body from void call [shasum] #2348
* TransFirst Transaction Express: Don't send order_id with refunds [curiousepic] #2350
* WePay: Update API version [shasum] #2349
* USA ePay Advanced: Add quick_update_customer action [joshreeves] #2229

== Version 1.63.0 (February 2, 2017)
* Authorize.net: Add #unstore support [jimryan] #2293
Expand Down
123 changes: 114 additions & 9 deletions lib/active_merchant/billing/gateways/usa_epay_advanced.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ class UsaEpayAdvancedGateway < Gateway
self.homepage_url = 'http://www.usaepay.com/'
self.display_name = 'USA ePay Advanced SOAP Interface'

CUSTOMER_OPTIONS = {
CUSTOMER_PROFILE_OPTIONS = {
:id => [:string, 'CustomerID'], # merchant assigned number
:notes => [:string, 'Notes'],
:data => [:string, 'CustomData'],
:url => [:string, 'URL'],
# Recurring Billing
:url => [:string, 'URL']
} #:nodoc:

CUSTOMER_RECURRING_BILLING_OPTIONS = {
:enabled => [:boolean, 'Enabled'],
:schedule => [:string, 'Schedule'],
:number_left => [:integer, 'NumLeft'],
Expand All @@ -92,18 +94,24 @@ class UsaEpayAdvancedGateway < Gateway
:user => [:string, 'User'],
:source => [:string, 'Source'],
:send_receipt => [:boolean, 'SendReceipt'],
:receipt_note => [:string, 'ReceiptNote'],
# Point of Sale
:receipt_note => [:string, 'ReceiptNote']
} #:nodoc:

CUSTOMER_POINT_OF_SALE_OPTIONS = {
:price_tier => [:string, 'PriceTier'],
:tax_class => [:string, 'TaxClass'],
:lookup_code => [:string, 'LookupCode']
} #:nodoc:

ADDRESS_OPTIONS = {
CUSTOMER_OPTIONS = [
CUSTOMER_PROFILE_OPTIONS,
CUSTOMER_RECURRING_BILLING_OPTIONS,
CUSTOMER_POINT_OF_SALE_OPTIONS
].inject(:merge) #:nodoc:

COMMON_ADDRESS_OPTIONS = {
:first_name => [:string, 'FirstName'],
:last_name => [:string, 'LastName'],
:address1 => [:string, 'Street'],
:address2 => [:string, 'Street2'],
:city => [:string, 'City'],
:state => [:string, 'State'],
:zip => [:string, 'Zip'],
Expand All @@ -114,6 +122,32 @@ class UsaEpayAdvancedGateway < Gateway
:company => [:string, 'Company']
} #:nodoc:

ADDRESS_OPTIONS = [
COMMON_ADDRESS_OPTIONS,
{
:address1 => [:string, 'Street'],
:address2 => [:string, 'Street2'],
}
].inject(:merge) #:nodoc

CUSTOMER_UPDATE_DATA_FIELDS = [
CUSTOMER_PROFILE_OPTIONS,
CUSTOMER_RECURRING_BILLING_OPTIONS,
COMMON_ADDRESS_OPTIONS,
{
:address1 => [:string, 'Address'],
:address2 => [:string, 'Address2'],
},
{
:card_number => [:string, 'CardNumber'],
:card_exp => [:string, 'CardExp'],
:account => [:string, 'Account'],
:routing => [:string, 'Routing'],
:check_format => [:string, 'CheckFormat'],
:record_type => [:string, 'RecordType'],
}
].inject(:merge) #:nodoc

CUSTOMER_TRANSACTION_REQUEST_OPTIONS = {
:command => [:string, 'Command'],
:ignore_duplicate => [:boolean, 'IgnoreDuplicate'],
Expand Down Expand Up @@ -354,6 +388,55 @@ def update_customer(options={})
commit(__method__, request)
end

# Update a customer by replacing only the provided fields.
#
# ==== Required
# * <tt>:customer_number</tt> -- customer to update
# * <tt>:update_data</tt> -- FieldValue array of fields to retrieve
# * <tt>:first_name</tt>
# * <tt>:last_name</tt>
# * <tt>:id</tt>
# * <tt>:company</tt>
# * <tt>:address</tt>
# * <tt>:address2</tt>
# * <tt>:city</tt>
# * <tt>:state</tt>
# * <tt>:zip</tt>
# * <tt>:country</tt>
# * <tt>:phone</tt>
# * <tt>:fax</tt>
# * <tt>:email</tt>
# * <tt>:url</tt>
# * <tt>:receipt_note</tt>
# * <tt>:send_receipt</tt>
# * <tt>:notes</tt>
# * <tt>:description</tt>
# * <tt>:order_id</tt>
# * <tt>:enabled</tt>
# * <tt>:schedule</tt>
# * <tt>:next</tt>
# * <tt>:num_left</tt>
# * <tt>:amount</tt>
# * <tt>:custom_data</tt>
# * <tt>:source</tt>
# * <tt>:user</tt>
# * <tt>:card_number</tt>
# * <tt>:card_exp</tt>
# * <tt>:account</tt>
# * <tt>:routing</tt>
# * <tt>:check_format</tt> or <tt>:record_type</tt>
#
# ==== Response
# * <tt>#message</tt> -- boolean; Returns true if successful. Exception thrown all failures.
#
def quick_update_customer(options={})
requires! options, :customer_number
requires! options, :update_data

request = build_request(__method__, options)
commit(__method__, request)
end

# Enable a customer for recurring billing.
#
# Note: Customer does not need to have all recurring parameters to succeed.
Expand Down Expand Up @@ -1019,6 +1102,14 @@ def build_delete_customer(soap, options)
build_customer(soap, options, 'deleteCustomer')
end

def build_quick_update_customer(soap, options)
soap.tag! "ns1:quickUpdateCustomer" do
build_token soap, options
build_tag soap, :integer, 'CustNum', options[:customer_number]
build_field_value_array soap, "UpdateData", "FieldValue", options[:update_data], CUSTOMER_UPDATE_DATA_FIELDS
end
end

def build_add_customer_payment_method(soap, options)
soap.tag! "ns1:addCustomerPaymentMethod" do
build_token soap, options
Expand Down Expand Up @@ -1408,6 +1499,21 @@ def build_shipping_address(soap, options)
end
end

def build_field_value_array(soap, tag_name, type, custom_data, fields)
soap.tag! tag_name, 'SOAP-ENC:arryType' => "xsd:#{type}[#{options.length}]", 'xsi:type' => "ns1:#{type}Array" do
custom_data.each do |k, v|
build_field_value soap, fields[k][1], v, fields[k][0] if fields.keys.include? k
end
end
end

def build_field_value(soap, field, value, value_type)
soap.FieldValue 'xsi:type' => 'ns1:FieldValue' do
build_tag soap, :string, 'Field', field
build_tag soap, value_type, 'Value', value
end
end

def build_line_items(soap, options) # TODO
end

Expand Down Expand Up @@ -1511,4 +1617,3 @@ def parse_element(node)
end
end
end

8 changes: 8 additions & 0 deletions test/remote/gateways/remote_usa_epay_advanced_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ def test_update_customer
assert response.params['update_customer_return']
end

def test_quick_update_customer
response = @gateway.add_customer(@options.merge(@customer_options))
customer_number = response.params['add_customer_return']

response = @gateway.quick_update_customer({customer_number: customer_number, update_data: @update_customer_options})
assert response.params['quick_update_customer_return']
end

def test_enable_disable_customer
response = @gateway.add_customer(@options.merge(@customer_options))
customer_number = response.params['add_customer_return']
Expand Down
12 changes: 12 additions & 0 deletions test/unit/gateways/usa_epay_advanced_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ def test_successful_update_customer
assert_nil response.authorization
end

def test_successful_quick_update_customer
@gateway.expects(:ssl_post).returns(successful_customer_response('quickUpdateCustomer'))

assert response = @gateway.quick_update_customer({customer_number: @options[:customer_number], update_data: @customer_options})
assert_instance_of Response, response
assert response.test?
assert_success response
assert_equal 'true', response.params['quick_update_customer_return']
assert_equal 'true', response.message
assert_nil response.authorization
end

def test_successful_enable_customer
@options.merge!(@standard_transaction_options)
@gateway.expects(:ssl_post).returns(successful_customer_response('enableCustomer'))
Expand Down

0 comments on commit c063a49

Please sign in to comment.