Skip to content

Commit 7581d0b

Browse files
authored
Merge branch 'master' into replace-fixnum-with-integer
2 parents bd92d70 + 647768c commit 7581d0b

13 files changed

Lines changed: 205 additions & 372 deletions

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ sudo:
44
false
55

66
rvm:
7-
- 2.1.0
8-
- 2.2.5
9-
- 2.3.1
10-
- 2.4.1
7+
- 2.2.7 # can't use the 2.2 alias because as of July 2017 travis resolves that to 2.2.0
8+
- 2.3
9+
- 2.4
1110

1211
before_script:
1312
- git submodule update --remote --recursive
File renamed without changes.

README.md

Lines changed: 66 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,111 @@
11
# Authorize.Net Ruby SDK
22

3-
[![Build Status](https://travis-ci.org/AuthorizeNet/sdk-ruby.png?branch=master)](https://travis-ci.org/AuthorizeNet/sdk-ruby)
4-
[![Coverage Status](https://coveralls.io/repos/AuthorizeNet/sdk-ruby/badge.svg?branch=master&service=github)](https://coveralls.io/github/AuthorizeNet/sdk-ruby?branch=master)
3+
[![Travis CI Status](https://travis-ci.org/AuthorizeNet/sdk-ruby.svg?branch=master)](https://travis-ci.org/AuthorizeNet/sdk-ruby)
4+
[![Coverage Status](https://coveralls.io/repos/github/AuthorizeNet/sdk-ruby/badge.svg?branch=master)](https://coveralls.io/github/AuthorizeNet/sdk-ruby?branch=master)
55
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/AuthorizeNet/sdk-ruby/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/AuthorizeNet/sdk-ruby/?branch=master)
6-
[![Gem Version](https://img.shields.io/gem/v/authorizenet.svg)](https://rubygems.org/gems/authorizenet)
6+
[![Gem Version](https://badge.fury.io/rb/authorizenet.svg)](https://badge.fury.io/rb/authorizenet)
77

8-
`gem install authorizenet`
98

10-
## Prerequisites
11-
12-
* Ruby 2.1.0 or higher
9+
## Requirements
10+
* Ruby 2.2.0 or higher
1311
* RubyGem 1.3.7 or higher (to build the gem)
1412
* RDoc 1.0 or higher (to build documentation)
1513
* Rake 0.8.7 or higher (to use the rake tasks)
1614
* Bundle 1.6 or higher
1715
* RSpec 2.1 or higher (to run rspec tests)
16+
* An Authorize.Net account (see _Registration & Configuration_ section below)
1817

19-
## Installation from rubygems.org
18+
### TLS 1.2
19+
The Authorize.Net APIs only support connections using the TLS 1.2 security protocol. It's important to make sure you have new enough versions of all required components to support TLS 1.2. Additionally, it's very important to keep these components up to date going forward to mitigate the risk of any security flaws that may be discovered in your system or any libraries it uses.
2020

21-
````
22-
> sudo gem install authorizenet
23-
````
24-
##
2521

26-
# Installation from project
22+
## Installation
2723

28-
````
24+
### Installation from rubygems.org
25+
```
26+
> sudo gem install authorizenet
27+
```
28+
29+
### Installation from project
30+
```
2931
> bundle install
3032
> rake gem
31-
> sudo gem install ./authorizenet-1.9.0.gem
32-
````
33-
## Registration & Configuration
33+
> sudo gem install ./authorizenet-1.9.3.gem
34+
```
3435

35-
Get a sandbox account at https://developer.authorize.net/sandbox/
36-
To run rspec tests, create a spec/credentials.yml with the following keys and the values obtained as described below.
37-
````
38-
#obtain an API login_id and transaction_id according to instructions at https://developer.authorize.net/faqs/#gettranskey
39-
api_login_id: {login_id_value}
40-
api_transaction_key: {transaction_key_value}
41-
#obtained md5 hash value by first setting the hash value in https://sandbox.authorize.net/ under the Account tab->MD5 Hash
42-
md5_value: {md5_value}
43-
````
44-
45-
## Usage
46-
Apart from this README, you can find details and examples of using the SDK in the following places:
47-
48-
- [Github Sample Code Repository](https://github.com/AuthorizeNet/sample-code-ruby)
49-
- [Developer Center Reference](http://developer.authorize.net/api/reference/index.html)
5036

51-
### Charging a Credit Card
52-
53-
````ruby
54-
require 'rubygems'
55-
require 'authorizenet'
56-
57-
include AuthorizeNet::API
58-
59-
transaction = Transaction.new('API_LOGIN', 'API_KEY', :gateway => :sandbox)
37+
## Registration & Configuration
38+
Use of this SDK and the Authorize.Net APIs requires having an account on our system. You can find these details in the Settings section.
39+
If you don't currently have a production Authorize.Net account and need a sandbox account for testing, you can easily sign up for one [here](https://developer.authorize.net/sandbox/).
6040

61-
request = CreateTransactionRequest.new
41+
### Authentication
42+
To authenticate with the Authorize.Net API you will need to use your account's API Login ID and Transaction Key. If you don't have these values, you can obtain them from our Merchant Interface site. Access the Merchant Interface for production accounts at (https://account.authorize.net/) or sandbox accounts at (https://sandbox.authorize.net).
6243

63-
request.transactionRequest = TransactionRequestType.new()
64-
request.transactionRequest.amount = 16.00
65-
request.transactionRequest.payment = PaymentType.new
66-
request.transactionRequest.payment.creditCard = CreditCardType.new('4242424242424242','0220','123')
67-
request.transactionRequest.transactionType = TransactionTypeEnum::AuthCaptureTransaction
68-
69-
response = transaction.create_transaction(request)
44+
Once you have your keys simply load them into the appropriate variables in your code, as per the below sample code dealing with the authentication part of the API request.
7045

71-
if response.messages.resultCode == MessageTypeEnum::Ok
72-
puts "Successful charge (auth + capture) (authorization code: #{response.transactionResponse.authCode})"
46+
#### To set your API credentials for an API request:
47+
```ruby
48+
transaction = Transaction.new('YOUR_API_LOGIN_ID', 'YOUR_TRANSACTION_KEY', :gateway => :sandbox)
49+
```
7350

74-
else
75-
puts response.messages.messages[0].text
76-
puts response.transactionResponse.errors.errors[0].errorCode
77-
puts response.transactionResponse.errors.errors[0].errorText
78-
raise "Failed to charge card."
79-
end
80-
````
51+
You should never include your Login ID and Transaction Key directly in a file that's in a publically accessible portion of your website. A better practice would be to define these in a constants file, and then reference those constants in the appropriate place in your code.
8152

82-
### Setting the Production Environment
83-
Replace the environment constant in the transaction instantiation. For example, in the method above:
53+
#### Setting OAuth credentials
54+
Access Tokens can be setup using the transaction instantiation without the constructor. For example, in the method above:
8455
```ruby
85-
transaction = Transaction.new('API_LOGIN', 'API_KEY', :gateway => :production)
56+
transaction = Transaction.new
57+
transaction.access_token = 'testTokenValue'
58+
transaction.options_OAuth = {:gateway => :sandbox, :verify_ssl => true}
8659
```
8760

88-
### Direct Post Method (DPM)
89-
90-
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.
91-
````
92-
> sudo gem install rails -v '>= 3.2'
93-
> sudo gem install authorizenet
94-
> rails new my_direct_post_app
95-
> cd my_direct_post_app
96-
````
97-
Edit Gemfile and add the line "gem 'authorizenet'"
98-
````
99-
> rails g authorize_net:direct_post payments YOUR_API_LOGIN_ID YOUR_TRANSACTION_KEY MERCH_HASH_KEY
100-
> rails server
101-
````
61+
### Switching between the sandbox environment and the production environment
62+
Authorize.Net maintains a complete sandbox environment for testing and development purposes. This sandbox environment is an exact duplicate of our production environment with the transaction authorization and settlement process simulated. By default, this SDK is configured to communicate with the sandbox environment. To switch to the production environment, replace the environment constant in the transaction instantiation. For example:
63+
```ruby
64+
# For PRODUCTION use
65+
transaction = Transaction.new('YOUR_API_LOGIN_ID', 'YOUR_TRANSACTION_KEY', :gateway => :production)
66+
```
10267

103-
After running the generator you will probably want to customize the payment form found in <tt>app/views/payments/payment.erb</tt> and the receipt found in <tt>app/views/payments/receipt.erb</tt>.
68+
API credentials are different for each environment, so be sure to switch to the appropriate credentials when switching environments.
10469

105-
There is also a default layout generated, <tt>app/views/layouts/authorize_net.erb</tt>. If you already have your own layout, you can delete that file and the reference to it in the controller (<tt>app/controllers/payments_controller.rb</tt>).
10670

107-
### Server Integration Method (SIM)
71+
## SDK Usage Examples and Sample Code
72+
To get started using this SDK, it's highly recommended to download our sample code repository:
73+
* [Authorize.Net Ruby Sample Code Repository (on GitHub)](https://github.com/AuthorizeNet/sample-code-ruby)
10874

109-
A generator is provided to aid in setting up a Server Integration Method application. In the example below +payments+ is the name of the controller to generate.
110-
````
111-
> sudo gem install rails -v '>= 3.2'
112-
> sudo gem install authorizenet
113-
> rails new my_sim_app
114-
> cd my_sim_app
115-
````
116-
Edit Gemfile and add the line "gem 'authorizenet'"
117-
````
118-
> rails g authorize_net:sim payments YOUR_API_LOGIN_ID YOUR_TRANSACTION_KEY MERCH_HASH_KEY
119-
> rails server
120-
````
121-
After running the generator you will probably want to customize the payment page found in <tt>app/views/payments/payment.erb</tt> and the thank you page found in <tt>app/views/payments/thank_you.erb</tt>.
75+
In that respository, we have comprehensive sample code for all common uses of our API:
12276

123-
You may also want to customize the actual payment form and receipt pages. That can be done by making the necessary changes to the AuthorizeNet::SIM::Transaction object (<tt>@sim_transaction</tt>) found in the +payment+ action in <tt>app/controllers/payments_controller.rb</tt>. The styling of those hosted pages are controlled by the AuthorizeNet::SIM::HostedReceiptPage and AuthorizeNet::SIM::HostedPaymentForm objects (which are passed to the AuthorizeNet::SIM::Transaction).
77+
Additionally, you can find details and examples of how our API is structured in our API Reference Guide:
78+
* [Developer Center API Reference](http://developer.authorize.net/api/reference/index.html)
12479

125-
There is also a default layout generated, <tt>app/views/layouts/authorize_net.erb</tt>. If you already have your own layout, you can delete that file and the reference to it in the controller (<tt>app/controllers/payments_controller.rb</tt>).
80+
The API Reference Guide provides examples of what information is needed for a particular request and how that information would be formatted. Using those examples, you can easily determine what methods would be necessary to include that information in a request using this SDK.
12681

12782

83+
## Building & Testing the SDK
12884

129-
## Running the Tests
85+
### Running the SDK Tests
13086
To run the integration tests (hitting the sandbox):
131-
````
87+
```
13288
rake spec
133-
````
89+
```
13490
To run the unit tests:
135-
````
91+
```
13692
rake spec:ci
137-
````
93+
```
13894

13995
To get spec/reporting_spec.rb to pass, go to https://sandbox.authorize.net/ under Account tab->Transaction Details API and enable it.
14096

97+
To run rspec tests, create a spec/credentials.yml with the following keys and the values obtained as described below.
98+
```ruby
99+
#obtain an API login_id and transaction_id according to instructions at https://developer.authorize.net/faqs/#gettranskey
100+
api_login_id: {login_id_value}
101+
api_transaction_key: {transaction_key_value}
102+
#obtained md5 hash value by first setting the hash value in https://sandbox.authorize.net/ under the Account tab->MD5 Hash
103+
md5_value: {md5_value}
104+
```
141105

142-
## Credit Card Test Numbers
143-
144-
For your reference, you can use the following test credit card numbers.
145-
The expiration date must be set to the present date or later. Use 123 for
146-
the CCV code.
147-
148-
* American Express: 370000000000002
149-
* Discover: 6011000000000012
150-
* Visa: 4007000000027
151-
* JCB: 3088000000000017
152-
* Diners Club/ Carte Blanche: 38000000000006
153-
* Visa (Card Present Track 1): %B4111111111111111^DOE/JOHN^1803101000000000020000831000000?
154-
155-
106+
### Testing Guide
107+
For additional help in testing your own code, Authorize.Net maintains a [comprehensive testing guide](http://developer.authorize.net/hello_world/testing_guide/) that includes test credit card numbers to use and special triggers to generate certain responses from the sandbox environment.
156108

157109

110+
## License
111+
This repository is distributed under a proprietary license. See the provided [`LICENSE.txt`](/LICENSE.txt) file.

0 commit comments

Comments
 (0)