Skip to content

Commit 6f88cea

Browse files
author
Sunny Raj Rathod
authored
Merge pull request #114 from namanbansal/master
Adding OAuth access token support
2 parents 3585a70 + d08adf7 commit 6f88cea

8 files changed

Lines changed: 54 additions & 11 deletions

File tree

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ rvm:
77
- 2.1.0
88
- 2.2.5
99
- 2.3.1
10+
- 2.2.7
11+
- 2.3.4
1012

1113
before_script:
1214
- git submodule update --remote --recursive

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ Replace the environment constant in the transaction instantiation. For example,
8585
transaction = Transaction.new('API_LOGIN', 'API_KEY', :gateway => :production)
8686
```
8787

88+
### Setting OAuth credentials
89+
Access Tokens can be setup using the transaction instantiation without the constructor. For example, in the method above:
90+
```ruby
91+
transaction = Transaction.new
92+
transaction.access_token = 'testTokenValue'
93+
transaction.options_OAuth = {:gateway => :sandbox, :verify_ssl => true}
94+
```
95+
8896
### Direct Post Method (DPM)
8997

9098
A generator is provided to aid in setting up a Direct Post Method application. In the example below +payments+ is the name of the controller to generate.

authorizenet.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Gem::Specification.new do |s|
22
s.name = "authorizenet"
3-
s.version = "1.9.2"
3+
s.version = "1.9.3"
44
s.platform = Gem::Platform::RUBY
5-
s.date = "2017-04-25"
5+
s.date = "2017-06-05"
66
s.summary = "Authorize.Net Payments SDK"
77
s.description = "Authorize.Net SDK includes standard payments, recurring billing, and customer profiles"
88
s.authors = ["Authorize.Net"]

lib/authorize_net/api/api_transaction.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@ module Type
5454

5555
end
5656

57-
def initialize(api_login_id, api_transaction_key, options = {})
57+
def initialize(api_login_id = nil, api_transaction_key = nil, options = {})
5858
super
5959
end
60-
60+
61+
def setOAuthOptions()
62+
super
63+
end
64+
6165
def make_request(request,responseClass,type)
62-
unless responseClass.nil? or request.nil?
66+
setOAuthOptions()
67+
unless responseClass.nil? or request.nil?
6368
begin
6469
@xml = serialize(request,type)
6570
respXml = send_request(@xml)
@@ -79,8 +84,13 @@ def serialize(object,type)
7984
builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |x|
8085
x.send(type.to_sym, :xmlns => XML_NAMESPACE) {
8186
x.merchantAuthentication {
82-
x.name @api_login_id
83-
x.transactionKey @api_transaction_key
87+
if !@access_token.blank?
88+
x.accessToken @access_token
89+
end
90+
if !@api_login_id.blank? || (@access_token.blank? && @api_login_id.blank?)
91+
x.name @api_login_id
92+
x.transactionKey @api_transaction_key
93+
end
8494
}
8595
x.clientId clientId
8696
x.send:insert, doc.root.element_children
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
clientId: sdk-ruby-1.9.2
1+
clientId: sdk-ruby-1.9.3

lib/authorize_net/api/schema.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ def initialize(hashValue = nil, sequence = nil, timestamp = nil, currencyCode =
784784
# impersonationAuthentication - ImpersonationAuthenticationType
785785
# fingerPrint - FingerPrintType
786786
# mobileDeviceId - SOAP::SOAPString
787+
# accessToken - SOAP::SOAPString
787788
class MerchantAuthenticationType
788789
include ROXML
789790
xml_accessor :name
@@ -793,15 +794,17 @@ class MerchantAuthenticationType
793794
xml_accessor :impersonationAuthentication, :as => ImpersonationAuthenticationType
794795
xml_accessor :fingerPrint, :as => FingerPrintType
795796
xml_accessor :mobileDeviceId
797+
xml_accessor :accessToken
796798

797-
def initialize(name = nil, transactionKey = nil, sessionToken = nil, password = nil, impersonationAuthentication = nil, fingerPrint = nil, mobileDeviceId = nil)
799+
def initialize(name = nil, transactionKey = nil, sessionToken = nil, password = nil, impersonationAuthentication = nil, fingerPrint = nil, mobileDeviceId = nil, accessToken = nil)
798800
@name = name
799801
@transactionKey = transactionKey
800802
@sessionToken = sessionToken
801803
@password = password
802804
@impersonationAuthentication = impersonationAuthentication
803805
@fingerPrint = fingerPrint
804806
@mobileDeviceId = mobileDeviceId
807+
@accessToken = accessToken
805808
end
806809
end
807810

lib/authorize_net/api/transaction.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
module AuthorizeNet::API
22
class Transaction < ApiTransaction
3-
4-
def initialize(api_login_id, api_transaction_key, options = {})
3+
attr_accessor :access_token
4+
attr_accessor :options_OAuth
5+
6+
def initialize(api_login_id = nil, api_transaction_key = nil, options = {})
57
super
68
end
79

lib/authorize_net/xml_transaction.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,24 @@ def initialize(api_login_id, api_transaction_key, options = {})
8787
end
8888
end
8989

90+
def setOAuthOptions()
91+
if !@options_OAuth.blank?
92+
@options_OAuth = @@option_defaults.merge(@options_OAuth)
93+
@verify_ssl = options_OAuth[:verify_ssl]
94+
@reference_id = options_OAuth[:reference_id]
95+
96+
@gateway = case options_OAuth[:gateway].to_s
97+
when 'sandbox', 'test'
98+
Gateway::TEST
99+
when 'production', 'live'
100+
Gateway::LIVE
101+
else
102+
@gateway = options_OAuth[:gateway]
103+
options_OAuth[:gateway]
104+
end
105+
end
106+
end
107+
90108
# Checks if the transaction has been configured for the sandbox or not. Return FALSE if the
91109
# transaction is running against the production, TRUE otherwise.
92110
def test?

0 commit comments

Comments
 (0)