Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

GatewayTransaction includes gateway_type #100

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ All notable changes to this project will be documented in this file.
### Added
- @almalee24 - Add MIT Framework support flag, supports_populate_mit_fields

## [2.0.24] - 2020-03-23
### Added
- @vpuzzella - GatewayTransaction includes gateway_type

## [2.0.24] - 2019-08-21
### Added
- @jeremywrowe - Add 3D Secure 2 complete transaction
Expand Down
1 change: 1 addition & 0 deletions lib/spreedly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require 'spreedly/payment_methods/bank_account'
require 'spreedly/payment_methods/third_party_token'
require 'spreedly/transactions/shipping_address'
require 'spreedly/transactions/network_tokenization'
require 'spreedly/transactions/response'
require 'spreedly/transactions/transaction'
require 'spreedly/transactions/gateway_transaction'
Expand Down
34 changes: 30 additions & 4 deletions lib/spreedly/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ def add_gateway(gateway_type, credentials = {})
Gateway.new(xml_doc)
end

def update_gateway(gateway_token, credentials: {}, options: {})
body = update_gateway_body(credentials: credentials, options: options)
puts body
xml_doc = ssl_put(update_gateway_url(gateway_token), body, headers)
Gateway.new(xml_doc)
end

def add_receiver(receiver_type, host_names = nil, credentials = [])
body = add_receiver_body(receiver_type, host_names, credentials)
xml_doc = ssl_post(add_receiver_url, body, headers)
Expand All @@ -158,6 +165,12 @@ def update_credit_card(credit_card_token, options)
PaymentMethod.new_from(xml_doc)
end

def update_gratis_credit_card(credit_card_token, options)
body = update_credit_card_body(options)
xml_doc = ssl_put(update_gratis_payment_method_url(credit_card_token), body, headers)
PaymentMethod.new_from(xml_doc)
end

def deliver_to_receiver(receiver_token, payment_method_token, receiver_options)
body = deliver_to_receiver_body(payment_method_token, receiver_options)
api_post(deliver_to_receiver_url(receiver_token), body)
Expand All @@ -180,6 +193,8 @@ def auth_purchase_body(amount, payment_method_token, options)
add_to_doc(doc, options, :retain_on_success)
add_to_doc(doc, options, :stored_credential_initiator)
add_to_doc(doc, options, :stored_credential_reason_type)
add_to_doc(doc, options, :provision_network_token)
add_to_doc(doc, options, :attempt_network_token)
add_extra_options_for_basic_ops(doc, options)
end
end
Expand All @@ -188,6 +203,10 @@ def verify_body(payment_method_token, options)
build_xml_request('transaction') do |doc|
doc.payment_method_token(payment_method_token)
add_to_doc(doc, options, :retain_on_success)
add_to_doc(doc, options, :stored_credential_initiator)
add_to_doc(doc, options, :stored_credential_reason_type)
add_to_doc(doc, options, :provision_network_token)
add_to_doc(doc, options, :attempt_network_token)
add_extra_options_for_basic_ops(doc, options)
end
end
Expand Down Expand Up @@ -240,6 +259,13 @@ def add_gateway_body(gateway_type, credentials)
end
end

def update_gateway_body(credentials: {}, options: {})
build_xml_request('gateway') do |doc|
add_to_doc(doc, credentials, *credentials.keys)
add_to_doc(doc, options, :description, :merchant_profile_key, :sub_merchant_key)
end
end

def add_receiver_body(receiver_type, host_names, credentials)
build_xml_request('receiver') do |doc|
doc.receiver_type receiver_type
Expand Down Expand Up @@ -267,20 +293,20 @@ def add_credentials_to_doc(doc, credentials)

def add_credit_card_body(options)
build_xml_request('payment_method') do |doc|
add_to_doc(doc, options, :data, :retained, :email)
add_to_doc(doc, options, :data, :retained, :email, :provision_network_token)
doc.credit_card do
add_to_doc(doc, options, :number, :verification_value, :month, :full_name, :first_name, :last_name,
:year, :address1, :address2, :city, :state, :zip, :country, :phone_number,
:company, :eligible_for_card_updater)
:company, :eligible_for_card_updater, :managed)
end
end
end

def update_credit_card_body(options)
build_xml_request('payment_method') do |doc|
add_to_doc(doc, options, :email, :month, :full_name, :first_name, :last_name, :year,
:address1, :address2, :city, :state, :zip, :country, :phone_number,
:eligible_for_card_updater)
:address1, :address2, :city, :state, :zip, :country, :phone_number, :managed,
:eligible_for_card_updater, :allow_blank_name, :allow_expired_date, :allow_blank_date)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/spreedly/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Spreedly

class Gateway < Model

field :gateway_type, :state, :name
field :gateway_type, :state, :name, :description
attr_reader :credentials

def initialize(xml_doc)
Expand Down
2 changes: 1 addition & 1 deletion lib/spreedly/payment_methods/credit_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class CreditCard < PaymentMethod
field :first_name, :last_name, :full_name, :month, :year
field :number, :last_four_digits, :first_six_digits, :card_type, :verification_value
field :address1, :address2, :city, :state, :zip, :country, :phone_number, :company, :fingerprint
field :eligible_for_card_updater, type: :boolean
field :eligible_for_card_updater, :managed, type: :boolean
end

end
2 changes: 1 addition & 1 deletion lib/spreedly/ssl_requester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def handle_response(response, return_raw)
when 402
raise PaymentRequiredError.new(xml_doc(response))
when 422
if xml_doc(response).at_xpath('.//errors/error')
if xml_doc(response).xpath('.//errors/error').reject { |e| e.parent.parent.name == 'network_tokenization' }.present?
raise TransactionCreationError.new(xml_doc(response))
else
xml_doc(response)
Expand Down
7 changes: 5 additions & 2 deletions lib/spreedly/transactions/gateway_transaction.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Spreedly
class GatewayTransaction < Transaction
field :order_id, :ip, :description, :gateway_token, :gateway_transaction_id, :email, :transaction_type
field :order_id, :ip, :description, :gateway_type, :gateway_token, :gateway_transaction_id, :email, :transaction_type
field :merchant_name_descriptor, :merchant_location_descriptor
field :on_test_gateway, type: :boolean

attr_reader :response, :gateway_specific_fields, :gateway_specific_response_fields, :shipping_address
attr_reader :response, :gateway_specific_fields, :gateway_specific_response_fields, :shipping_address, :network_tokenization

def initialize(xml_doc)
super
Expand All @@ -14,6 +14,9 @@ def initialize(xml_doc)
@shipping_address = shipping_address_xml_doc ? ShippingAddress.new(shipping_address_xml_doc) : nil
@gateway_specific_fields = parse_gateway_fields(xml_doc, './/gateway_specific_fields')
@gateway_specific_response_fields = parse_gateway_fields(xml_doc, './/gateway_specific_response_fields')

network_tokenization_xml_doc = xml_doc.at_xpath('.//network_tokenization')
@network_tokenization = network_tokenization_xml_doc ? NetworkTokenization.new(network_tokenization_xml_doc) : nil
end

def parse_gateway_fields(xml_doc, path)
Expand Down
15 changes: 15 additions & 0 deletions lib/spreedly/transactions/network_tokenization.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Spreedly
class NetworkTokenization
include Fields
include ErrorsParser

field :provisioned, type: :boolean
field :token_status
attr_reader :errors

def initialize(xml_doc)
initialize_fields(xml_doc)
@errors = errors_from(xml_doc)
end
end
end
8 changes: 8 additions & 0 deletions lib/spreedly/urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def add_gateway_url
"#{base_url}/v1/gateways.xml"
end

def update_gateway_url(gateway_token)
"#{base_url}/v1/gateways/#{gateway_token}.xml"
end

def receiver_options_url
"#{base_url}/v1/receivers_options.xml"
end
Expand All @@ -118,6 +122,10 @@ def update_payment_method_url(token)
"#{base_url}/v1/payment_methods/#{token}.xml"
end

def update_gratis_payment_method_url(token)
"#{base_url}/v1/payment_methods/#{token}/update_gratis.xml"
end

def deliver_to_receiver_url(receiver_token)
"#{base_url}/v1/receivers/#{receiver_token}/deliver.xml"
end
Expand Down
1 change: 1 addition & 0 deletions test/unit/purchase_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_successful_purchase
assert_equal '4 Shardblades', t.description
assert_equal '', t.merchant_name_descriptor
assert_equal '', t.merchant_location_descriptor
assert_equal 'test', t.gateway_type
assert_equal 'YOaCn5a9xRaBTGgmGAWbkgWUuqv', t.gateway_token
assert_equal '8xXXIPGXTaPXysDA5OUpgnjTEjK', t.payment_method.token
assert_equal "44", t.gateway_transaction_id
Expand Down
1 change: 1 addition & 0 deletions test/unit/refund_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_successful_refund
assert_equal 'LotsOCoffee', t.description
assert_equal 'My Writeoff Inc.', t.merchant_name_descriptor
assert_equal 'Tax Free Zone', t.merchant_location_descriptor
assert_equal 'test', t.gateway_type
assert_equal 'XYI0V2l4KC1cAm6Y3c2kG5loJaA', t.gateway_token
assert_equal 'RkIAltzr49eXuWc7ajBjLLeKZt8', t.reference_token
assert_equal 'Credit', t.transaction_type
Expand Down
1 change: 1 addition & 0 deletions test/unit/response_stubs/purchase_stubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def successful_purchase_response
<gateway_specific_fields nil="true"/>
<gateway_specific_response_fields nil="true"/>
<message key="messages.transaction_succeeded">Succeeded!</message>
<gateway_type>test</gateway_type>
<gateway_token>YOaCn5a9xRaBTGgmGAWbkgWUuqv</gateway_token>
<gateway_transaction_id>44</gateway_transaction_id>
<three_ds_context>three-ds-context</three_ds_context>
Expand Down
1 change: 1 addition & 0 deletions test/unit/response_stubs/refund_stubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def successful_refund_response
<gateway_specific_fields nil="true"/>
<gateway_specific_response_fields nil="true"/>
<message key="messages.transaction_succeeded">Succeeded!</message>
<gateway_type>test</gateway_type>
<gateway_token>XYI0V2l4KC1cAm6Y3c2kG5loJaA</gateway_token>
<gateway_transaction_id>44</gateway_transaction_id>
<response>
Expand Down