Skip to content

Commit fde504c

Browse files
authored
Merge branch 'master' into appraisal
2 parents 205553c + f4317ff commit fde504c

11 files changed

Lines changed: 162 additions & 377 deletions

File tree

.travis.yml

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

66
rvm:
7-
- 2.1
8-
- 2.2.7
7+
- 2.2.7 # can't use the 2.2 alias because as of July 2017 travis resolves that to 2.2.0
98
- 2.3
109
- 2.4
1110

@@ -20,11 +19,4 @@ before_script:
2019
script:
2120
- bundle exec rake spec:ci
2221
- bundle exec rake spec:api
23-
- bundle exec rake spec:testrunner
24-
25-
matrix:
26-
exclude:
27-
- rvm: 2.1
28-
gemfile: gemfiles/rails_50.gemfile
29-
- rvm: 2.1
30-
gemfile: gemfiles/rails_51.gemfile
22+
- bundle exec rake spec:testrunner
File renamed without changes.

README.md

Lines changed: 62 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +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
34-
35-
Get a sandbox account at https://developer.authorize.net/hello_world/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)
50-
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)
33+
> sudo gem install ./authorizenet-1.9.3.gem
34+
```
6035

61-
request = CreateTransactionRequest.new
6236

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)
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/).
7040

71-
if response.messages.resultCode == MessageTypeEnum::Ok
72-
puts "Successful charge (auth + capture) (authorization code: #{response.transactionResponse.authCode})"
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).
7343

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-
````
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.
8145

82-
### Setting the Production Environment
83-
Replace the environment constant in the transaction instantiation. For example, in the method above:
46+
#### To set your API credentials for an API request:
8447
```ruby
85-
transaction = Transaction.new('API_LOGIN', 'API_KEY', :gateway => :production)
86-
```
48+
transaction = Transaction.new('YOUR_API_LOGIN_ID', 'YOUR_TRANSACTION_KEY', :gateway => :sandbox)
49+
```
50+
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.
8752

88-
### Setting OAuth credentials
53+
#### Setting OAuth credentials
8954
Access Tokens can be setup using the transaction instantiation without the constructor. For example, in the method above:
9055
```ruby
9156
transaction = Transaction.new
9257
transaction.access_token = 'testTokenValue'
9358
transaction.options_OAuth = {:gateway => :sandbox, :verify_ssl => true}
9459
```
9560

96-
### Direct Post Method (DPM)
97-
98-
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.
99-
````
100-
> sudo gem install rails -v '>= 3.2'
101-
> sudo gem install authorizenet
102-
> rails new my_direct_post_app
103-
> cd my_direct_post_app
104-
````
105-
Edit Gemfile and add the line "gem 'authorizenet'"
106-
````
107-
> rails g authorize_net:direct_post payments YOUR_API_LOGIN_ID YOUR_TRANSACTION_KEY MERCH_HASH_KEY
108-
> rails server
109-
````
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+
```
11067

111-
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.
11269

113-
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>).
11470

115-
### 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)
11674

117-
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.
118-
````
119-
> sudo gem install rails -v '>= 3.2'
120-
> sudo gem install authorizenet
121-
> rails new my_sim_app
122-
> cd my_sim_app
123-
````
124-
Edit Gemfile and add the line "gem 'authorizenet'"
125-
````
126-
> rails g authorize_net:sim payments YOUR_API_LOGIN_ID YOUR_TRANSACTION_KEY MERCH_HASH_KEY
127-
> rails server
128-
````
129-
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:
13076

131-
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)
13279

133-
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.
13481

13582

83+
## Building & Testing the SDK
13684

137-
## Running the Tests
85+
### Running the SDK Tests
13886
To run the integration tests (hitting the sandbox):
139-
````
87+
```
14088
rake spec
141-
````
89+
```
14290
To run the unit tests:
143-
````
91+
```
14492
rake spec:ci
145-
````
93+
```
14694

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

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+
```
149105

150-
## Credit Card Test Numbers
151-
152-
For your reference, you can use the following test credit card numbers.
153-
The expiration date must be set to the present date or later. Use 123 for
154-
the CCV code.
155-
156-
* American Express: 370000000000002
157-
* Discover: 6011000000000012
158-
* Visa: 4007000000027
159-
* JCB: 3088000000000017
160-
* Diners Club/ Carte Blanche: 38000000000006
161-
* Visa (Card Present Track 1): %B4111111111111111^DOE/JOHN^1803101000000000020000831000000?
162-
163-
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.
164108

165109

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

0 commit comments

Comments
 (0)