tres_delta 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/config/three_delta.sample.yml +9 -0
- data/lib/tres_delta/client.rb +49 -0
- data/lib/tres_delta/config.rb +11 -0
- data/lib/tres_delta/credit_card/address.rb +12 -0
- data/lib/tres_delta/credit_card.rb +16 -0
- data/lib/tres_delta/customer.rb +14 -0
- data/lib/tres_delta/gateway.rb +61 -0
- data/lib/tres_delta/response.rb +21 -0
- data/lib/tres_delta/vault.rb +72 -0
- data/lib/tres_delta/version.rb +3 -0
- data/lib/tres_delta.rb +16 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/tres_delta/client_spec.rb +24 -0
- data/spec/tres_delta/customer_spec.rb +28 -0
- data/spec/tres_delta/gateway_spec.rb +106 -0
- data/spec/tres_delta/vault_spec.rb +153 -0
- data/tres_delta.gemspec +26 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 42fa12ff320aeb5b1c3e547012cfb12de4750034
|
4
|
+
data.tar.gz: 41d94636dc3b346b47eb20a60347944bf837c878
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d71952aecaebdd6e3790d2fa9e5bc5555e11a16859aad80ea3bd571b569e8d4cedada9b9a4d08fd47c75ca95c85c0d358fdd6f97a8314e2d8681bdbd45e7c60f
|
7
|
+
data.tar.gz: 64e8999d46eef97455ff886b03a3555bca270099615639303ca17f412b95781307b091a62c25e90a6eb437e65a1fef9a9eea555ee96d36db890ed8bcdeffbe88
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
tres_delta
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Zachary Danger Campbell
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# TresDelta
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tres_delta'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tres_delta
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
---
|
2
|
+
client_code: User
|
3
|
+
user_name: Linxtrans
|
4
|
+
password: Sample3c0de
|
5
|
+
merchant_code: User
|
6
|
+
location_code: Location1
|
7
|
+
terminal_code: Terminal1
|
8
|
+
management_wsdl: https://services.PWSDemo.com/CreditCardManagementService.svc?wsdl
|
9
|
+
transaction_wsdl: https://services.PWSDemo.com/CreditCardTransactionService.svc?wsdl
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'savon'
|
2
|
+
|
3
|
+
module TresDelta
|
4
|
+
class Client
|
5
|
+
attr_accessor :wsdl
|
6
|
+
|
7
|
+
def initialize(wsdl)
|
8
|
+
@wsdl = wsdl
|
9
|
+
end
|
10
|
+
|
11
|
+
def request(action, soap_body)
|
12
|
+
Response.create_from_action(action, client.call(action, message: soap_body))
|
13
|
+
end
|
14
|
+
|
15
|
+
def client_credentials
|
16
|
+
{
|
17
|
+
"ClientCode" => config["client_code"],
|
18
|
+
"Password" => config["password"],
|
19
|
+
"UserName" => config["user_name"]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def location_identifier
|
24
|
+
{
|
25
|
+
'LocationCode' => config["location_code"],
|
26
|
+
'MerchantCode' => config["merchant_code"]
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def client
|
31
|
+
# TODO: Make this configurable via file. Because right now this ain't secure. -_-
|
32
|
+
@client ||= ::Savon.client(savon_options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def savon_options
|
36
|
+
default_savon_options.merge(savon_overrides || {})
|
37
|
+
end
|
38
|
+
|
39
|
+
def default_savon_options
|
40
|
+
{ wsdl: wsdl, ssl_version: :SSLv3, ssl_verify_mode: :none, log: false }
|
41
|
+
end
|
42
|
+
|
43
|
+
def savon_overrides; end
|
44
|
+
|
45
|
+
def config
|
46
|
+
Config.config
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module TresDelta
|
2
|
+
class CreditCard
|
3
|
+
attr_reader :number, :expiration_month, :expiration_year, :token, :name, :billing_address, :type, :nickname
|
4
|
+
|
5
|
+
def initialize(params = {})
|
6
|
+
@number = params[:number]
|
7
|
+
@expiration_month = params[:expiration_month]
|
8
|
+
@expiration_year = params[:expiration_year]
|
9
|
+
@token = params[:token]
|
10
|
+
@name = params[:name]
|
11
|
+
@billing_address = Address.new(params[:billing_address] || {})
|
12
|
+
@type = params[:type]
|
13
|
+
@nickname = params[:nickname]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module TresDelta
|
2
|
+
class Gateway < Client
|
3
|
+
def initialize
|
4
|
+
@wsdl = Config.config['transaction_wsdl']
|
5
|
+
end
|
6
|
+
|
7
|
+
def card_verification(transaction_key, credit_card)
|
8
|
+
request(:card_verification, card_verification_params(transaction_key, credit_card))
|
9
|
+
end
|
10
|
+
|
11
|
+
def card_verification_params(transaction_key, credit_card)
|
12
|
+
{
|
13
|
+
'clientCredentials' => client_credentials,
|
14
|
+
'cardVerificationParams' => {
|
15
|
+
'AddOrUpdateCard' => 'false',
|
16
|
+
'CreditCard' => credit_card_params(credit_card),
|
17
|
+
'TerminalIdentifier' => terminal_identifier,
|
18
|
+
'TransactionKey' => transaction_key
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def credit_card_params(credit_card)
|
24
|
+
{
|
25
|
+
'cc:BillingAddress' => billing_address_params(credit_card.billing_address),
|
26
|
+
'cc:CardAccountNumber' => credit_card.number,
|
27
|
+
'cc:ExpirationMonth' => credit_card.expiration_month,
|
28
|
+
'cc:ExpirationYear' => credit_card.expiration_year,
|
29
|
+
'NameOnCard' => credit_card.name,
|
30
|
+
'CardSecurityCode' => nil,
|
31
|
+
'CardSecurityCodeIndicator' => 'None'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def billing_address_params(billing_address)
|
36
|
+
{
|
37
|
+
'cc:AddressLine1' => billing_address.address,
|
38
|
+
'cc:PostalCode' => billing_address.zip_code
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def terminal_identifier
|
43
|
+
{
|
44
|
+
'LocationCode' => config['location_code'],
|
45
|
+
'MerchantCode' => config['merchant_code'],
|
46
|
+
'TerminalCode' => config['terminal_code']
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def savon_overrides
|
51
|
+
{
|
52
|
+
namespaces: {
|
53
|
+
'xmlns:cc' => 'http://schemas.datacontract.org/2004/07/ThreeDelta.Web.Services.ECLinx.Definitions'
|
54
|
+
}
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def authorize(transaction_key, credit_card, transaction_total, order_number)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module TresDelta
|
2
|
+
class Response
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@response = response
|
7
|
+
end
|
8
|
+
|
9
|
+
def success?
|
10
|
+
@response[:succeeded]
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(method, *args)
|
14
|
+
@response[method]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.create_from_action(action, response)
|
18
|
+
self.new(response.body["#{action}_response".to_sym]["#{action}_result".to_sym])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module TresDelta
|
2
|
+
class Vault < Client
|
3
|
+
def initialize
|
4
|
+
@wsdl = Config.config['management_wsdl']
|
5
|
+
end
|
6
|
+
|
7
|
+
def create_customer(customer)
|
8
|
+
request(:create_customer, create_customer_params(customer))
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_customer_params(customer)
|
12
|
+
{
|
13
|
+
'clientCredentials' => client_credentials,
|
14
|
+
'createCustomerParams' => {
|
15
|
+
'Customer' => {
|
16
|
+
'Code' => customer.vault_key,
|
17
|
+
'Name' => customer.name
|
18
|
+
},
|
19
|
+
'LocationIdentifier' => location_identifier
|
20
|
+
}
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_stored_credit_card(customer, credit_card)
|
25
|
+
request(:add_stored_credit_card, add_stored_credit_card_params(customer, credit_card))
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_stored_credit_card_params(customer, credit_card)
|
29
|
+
{
|
30
|
+
'clientCredentials' => client_credentials,
|
31
|
+
'addStoredCardParams' => {
|
32
|
+
'CreditCard' => {
|
33
|
+
'CardAccountNumber' => credit_card.number,
|
34
|
+
'CardType' => credit_card.type,
|
35
|
+
'Cardholder' => {
|
36
|
+
'FirstName' => credit_card.name,
|
37
|
+
'LastName' => nil
|
38
|
+
},
|
39
|
+
'ExpirationMonth' => credit_card.expiration_month,
|
40
|
+
'ExpirationYear' => credit_card.expiration_year,
|
41
|
+
'NameOnCard' => credit_card.name,
|
42
|
+
'FriendlyName' => credit_card.nickname
|
43
|
+
},
|
44
|
+
'CustomerIdentifier' => customer_identifier(customer)
|
45
|
+
}
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def customer_identifier(customer)
|
50
|
+
{
|
51
|
+
'CustomerCode' => customer.vault_key,
|
52
|
+
'LocationCode' => config["location_code"],
|
53
|
+
'MerchantCode' => config["merchant_code"]
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_stored_credit_card(customer, token, include_card_number = false)
|
58
|
+
request(:get_stored_credit_card, get_stored_credit_card_params(customer, token, include_card_number))
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_stored_credit_card_params(customer, token, include_card_number)
|
62
|
+
{
|
63
|
+
'clientCredentials' => client_credentials,
|
64
|
+
'getStoredCreditCardParams' => {
|
65
|
+
'CustomerIdentifier' => customer_identifier(customer),
|
66
|
+
'RetrieveCardNumber' => include_card_number ? 'true' : 'false',
|
67
|
+
'Token' => token
|
68
|
+
}
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/tres_delta.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "tres_delta/version"
|
2
|
+
require "tres_delta/client"
|
3
|
+
require "tres_delta/config"
|
4
|
+
require "tres_delta/credit_card"
|
5
|
+
require "tres_delta/credit_card/address"
|
6
|
+
require "tres_delta/customer"
|
7
|
+
require "tres_delta/gateway"
|
8
|
+
require "tres_delta/response"
|
9
|
+
require "tres_delta/vault"
|
10
|
+
|
11
|
+
module TresDelta
|
12
|
+
class Errors
|
13
|
+
CARD_NUMBER_IN_USE = "CardNumberInUse"
|
14
|
+
VALIDATION_FAILED = "ValidationFailed"
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
require 'tres_delta'
|
5
|
+
|
6
|
+
config_file = File.expand_path(File.join(File.dirname(__FILE__), '../config/three_delta.yml'))
|
7
|
+
|
8
|
+
unless File.exists?(config_file)
|
9
|
+
puts "You must have a config/three_delta.yml file. See config/three_delta.sample.yml for proper format"
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'yaml'
|
14
|
+
|
15
|
+
TresDelta::Config.config = YAML.load_file(config_file)
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
# TODO: CONFIGURE SOME RSPEC
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TresDelta::Client do
|
4
|
+
let(:wsdl) { "http://example.com" }
|
5
|
+
|
6
|
+
let(:client) { TresDelta::Client.new(wsdl) }
|
7
|
+
let(:config) { TresDelta::Config.config }
|
8
|
+
|
9
|
+
describe "#client_credentials" do
|
10
|
+
it "uses the credentials passed into it" do
|
11
|
+
client.client_credentials.should == {
|
12
|
+
"ClientCode" => config["client_code"],
|
13
|
+
"Password" => config["password"],
|
14
|
+
"UserName" => config["user_name"]
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#client" do
|
20
|
+
it "returns a Savon client for the WSDL" do
|
21
|
+
client.client.class.should == Savon::Client
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TresDelta::Customer do
|
4
|
+
describe "initalization" do
|
5
|
+
let(:name) { "Johnny B" }
|
6
|
+
|
7
|
+
context "new customer" do
|
8
|
+
let(:customer) { TresDelta::Customer.new(:name => name) }
|
9
|
+
|
10
|
+
it "generates a random vault key" do
|
11
|
+
expect(customer.vault_key.size).to eq(24)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "uses the assigned name" do
|
15
|
+
expect(customer.name).to eq(name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "existing customer" do
|
20
|
+
let(:vault_key) { SecureRandom.hex(12) }
|
21
|
+
let(:customer) { TresDelta::Customer.new(:vault_key => vault_key) }
|
22
|
+
|
23
|
+
it "is initialized with a given vault key" do
|
24
|
+
expect(customer.vault_key).to eq(vault_key)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TresDelta::Gateway do
|
4
|
+
let(:gateway) { TresDelta::Gateway.new }
|
5
|
+
let(:transaction_key) { SecureRandom.hex(6) }
|
6
|
+
let(:customer) { TresDelta::Customer.new(name: 'FOO BAR') }
|
7
|
+
|
8
|
+
let(:credit_card) do
|
9
|
+
TresDelta::CreditCard.new({
|
10
|
+
number: '4242424242424242',
|
11
|
+
expiration_month: '03',
|
12
|
+
expiration_year: Time.now.strftime("%Y").to_i + 3,
|
13
|
+
name: 'Joe Customer',
|
14
|
+
type: 'Visa',
|
15
|
+
nickname: 'Test Visa, Yo.',
|
16
|
+
billing_address: address_params
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
it "has a goddamn wsdl" do
|
21
|
+
expect(gateway.wsdl).to eq(TresDelta::Config.config['transaction_wsdl'])
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "credit card address verification" do
|
25
|
+
context "full credit card information" do
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with a token" do
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "credit card zip code verification" do
|
33
|
+
# arbitrary: Cisco, TX
|
34
|
+
let(:zip_code_good) { '76437' }
|
35
|
+
|
36
|
+
# magic numbers, see ThreeDelta docs
|
37
|
+
let(:zip_code_failure) { '20151' }
|
38
|
+
let(:zip_code_unavailable) { '32561' }
|
39
|
+
let(:zip_code_error) { '80201' }
|
40
|
+
|
41
|
+
let(:address_params) { { :zip_code => zip_code } }
|
42
|
+
|
43
|
+
let(:response) { gateway.card_verification(transaction_key, credit_card) }
|
44
|
+
|
45
|
+
context "good zip code" do
|
46
|
+
let(:zip_code) { zip_code_good }
|
47
|
+
|
48
|
+
it "passes aip code avs" do
|
49
|
+
expect(response.success?).to be_true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "zip code failure" do
|
54
|
+
let(:zip_code) { zip_code_failure }
|
55
|
+
|
56
|
+
it "fails the zip code avs" do
|
57
|
+
expect(response.success?).to be_true
|
58
|
+
expect(response.postal_code_avs_response).to eq("NotMatched")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "zip code unavailable" do
|
63
|
+
let(:zip_code) { zip_code_unavailable }
|
64
|
+
|
65
|
+
it "doesn't really fail the avs check" do
|
66
|
+
expect(response.success?).to be_true
|
67
|
+
expect(response.postal_code_avs_response).to eq("Unavailable")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "zip code avs error" do
|
72
|
+
let(:zip_code) { zip_code_error }
|
73
|
+
|
74
|
+
it "doesn't fail per se" do
|
75
|
+
expect(response.success?).to be_true
|
76
|
+
expect(response.postal_code_avs_response).to eq("Error")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "credit card address verificaiton" do
|
82
|
+
let(:good_address) { "10124 Brentridge Ct" }
|
83
|
+
let(:bad_address) { "14151 Brentridge Ct" }
|
84
|
+
let(:address_params) { { :address => address } }
|
85
|
+
|
86
|
+
let(:response) { gateway.card_verification(transaction_key, credit_card) }
|
87
|
+
|
88
|
+
context "good address" do
|
89
|
+
let(:address) { good_address }
|
90
|
+
|
91
|
+
it "passes avs" do
|
92
|
+
expect(response.success?).to be_true
|
93
|
+
expect(response.address_avs_response).to eq('Matched')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "bad address" do
|
98
|
+
let(:address) { bad_address }
|
99
|
+
|
100
|
+
it "fails avs" do
|
101
|
+
expect(response.success?).to be_true
|
102
|
+
expect(response.address_avs_response).to eq('NotMatched')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TresDelta::Vault do
|
4
|
+
let(:config) { TresDelta::Config.config }
|
5
|
+
let(:wsdl) { config["management_wsdl"] }
|
6
|
+
let(:customer) { TresDelta::Customer.new(name: name) }
|
7
|
+
let(:name) { SecureRandom.hex(4) }
|
8
|
+
let(:vault) { TresDelta::Vault.new }
|
9
|
+
|
10
|
+
let(:good_visa) do
|
11
|
+
TresDelta::CreditCard.new({
|
12
|
+
number: '4111111111111111',
|
13
|
+
expiration_month: '8',
|
14
|
+
expiration_year: Time.now.strftime("%Y").to_i + 3,
|
15
|
+
name: 'Joe Customer',
|
16
|
+
type: 'Visa',
|
17
|
+
nickname: 'Test Visa, Yo.'
|
18
|
+
})
|
19
|
+
end
|
20
|
+
|
21
|
+
it "uses the WSDL from the global config" do
|
22
|
+
expect(vault.wsdl).to eq(wsdl)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe ".create_customer" do
|
26
|
+
let!(:response) { vault.create_customer(customer) }
|
27
|
+
|
28
|
+
it "is successful" do
|
29
|
+
expect(response.success?).to be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
context "try to create a customer again" do
|
33
|
+
it "fails horribly" do
|
34
|
+
repeat_response = vault.create_customer(customer)
|
35
|
+
expect(repeat_response.success?).to be_false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe ".add_stored_credit_card" do
|
41
|
+
let(:customer) { TresDelta::Customer.new(name: 'Test Customer') }
|
42
|
+
let(:vault) { TresDelta::Vault.new }
|
43
|
+
|
44
|
+
before(:each) do
|
45
|
+
vault.create_customer(customer)
|
46
|
+
end
|
47
|
+
|
48
|
+
context "a good credit card" do
|
49
|
+
let(:response) { vault.add_stored_credit_card(customer, good_visa) }
|
50
|
+
|
51
|
+
it "saves the damn credit card" do
|
52
|
+
response.success?.should be_true
|
53
|
+
end
|
54
|
+
|
55
|
+
it "has a token" do
|
56
|
+
expect(response.token).to_not be_nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "a duplicate credit card" do
|
61
|
+
let!(:first_response) { vault.add_stored_credit_card(customer, good_visa) }
|
62
|
+
let(:response) { vault.add_stored_credit_card(customer, good_visa) }
|
63
|
+
|
64
|
+
it "fails to save the card probably" do
|
65
|
+
expect(response.success?).to be_false
|
66
|
+
end
|
67
|
+
|
68
|
+
it "has a card number in use failure reason" do
|
69
|
+
expect(response.failure_reason).to eq(TresDelta::Errors::CARD_NUMBER_IN_USE)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "bad type" do
|
74
|
+
let(:bad_visa) do
|
75
|
+
TresDelta::CreditCard.new({
|
76
|
+
number: '4111111111111111',
|
77
|
+
expiration_month: '8',
|
78
|
+
expiration_year: Time.now.strftime("%Y").to_i + 3,
|
79
|
+
name: 'Joe Customer',
|
80
|
+
type: 'MasterCard',
|
81
|
+
nickname: 'Test Visa, Yo.'
|
82
|
+
})
|
83
|
+
end
|
84
|
+
|
85
|
+
let(:response) { vault.add_stored_credit_card(customer, bad_visa) }
|
86
|
+
|
87
|
+
it "doesn't save the card" do
|
88
|
+
expect(response.success?).to be_false
|
89
|
+
end
|
90
|
+
|
91
|
+
it "has validation errors" do
|
92
|
+
expect(response.validation_failures.size).to be > 0
|
93
|
+
end
|
94
|
+
|
95
|
+
it "has a failure reason" do
|
96
|
+
expect(response.failure_reason).to eq(TresDelta::Errors::VALIDATION_FAILED)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "get_stored_credit_card", :focus => true do
|
102
|
+
let(:include_card_number) { false }
|
103
|
+
let(:response) { vault.get_stored_credit_card(customer, token, include_card_number) }
|
104
|
+
|
105
|
+
before(:each) do
|
106
|
+
vault.create_customer(customer)
|
107
|
+
end
|
108
|
+
|
109
|
+
context "card doesn't exist" do
|
110
|
+
let(:token) { SecureRandom.hex(6) } # random, lol
|
111
|
+
|
112
|
+
it "fails" do
|
113
|
+
expect(response.success?).to be_false
|
114
|
+
expect(response.failure_reason).to eq('CreditCardDoesNotExist')
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "card exists" do
|
119
|
+
let(:token) { vault.add_stored_credit_card(customer, good_visa).token }
|
120
|
+
let(:card_data) { response.credit_card }
|
121
|
+
|
122
|
+
context "card number not included" do
|
123
|
+
it "is successful" do
|
124
|
+
expect(response.success?).to be_true
|
125
|
+
end
|
126
|
+
|
127
|
+
it "contains the details of the credit card" do
|
128
|
+
expect(card_data[:expiration_month]).to eq(good_visa.expiration_month.to_s)
|
129
|
+
expect(card_data[:expiration_year]).to eq(good_visa.expiration_year.to_s)
|
130
|
+
expect(card_data[:name_on_card]).to eq(good_visa.name)
|
131
|
+
expect(card_data[:friendly_name]).to eq(good_visa.nickname)
|
132
|
+
expect(card_data[:token]).to eq(token)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "doesn't contain the credit card number" do
|
136
|
+
expect(card_data[:card_account_number]).to be_nil
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "card number included" do
|
141
|
+
let(:include_card_number) { true }
|
142
|
+
|
143
|
+
it "is successful" do
|
144
|
+
expect(response.success?).to be_true
|
145
|
+
end
|
146
|
+
|
147
|
+
it "contains the credit card number" do
|
148
|
+
expect(card_data[:card_account_number]).to eq(good_visa.number)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
data/tres_delta.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tres_delta/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tres_delta"
|
8
|
+
spec.version = TresDelta::VERSION
|
9
|
+
spec.authors = ["1000Bulbs", "Zachary Danger Campbell"]
|
10
|
+
spec.email = ["zacharydangercampbell@gmail.com"]
|
11
|
+
spec.description = %q{A Ruby client for ThreeDelta's credit card vault and payment gateway.}
|
12
|
+
spec.summary = %q{A Ruby client for ThreeDelta's credit card vault and payment gateway.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "savon", "2.3.3"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.4"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tres_delta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 1000Bulbs
|
8
|
+
- Zachary Danger Campbell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: savon
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.3.3
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.3.3
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.4'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.4'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: A Ruby client for ThreeDelta's credit card vault and payment gateway.
|
71
|
+
email:
|
72
|
+
- zacharydangercampbell@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".ruby-gemset"
|
79
|
+
- ".ruby-version"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- config/three_delta.sample.yml
|
85
|
+
- lib/tres_delta.rb
|
86
|
+
- lib/tres_delta/client.rb
|
87
|
+
- lib/tres_delta/config.rb
|
88
|
+
- lib/tres_delta/credit_card.rb
|
89
|
+
- lib/tres_delta/credit_card/address.rb
|
90
|
+
- lib/tres_delta/customer.rb
|
91
|
+
- lib/tres_delta/gateway.rb
|
92
|
+
- lib/tres_delta/response.rb
|
93
|
+
- lib/tres_delta/vault.rb
|
94
|
+
- lib/tres_delta/version.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
- spec/tres_delta/client_spec.rb
|
97
|
+
- spec/tres_delta/customer_spec.rb
|
98
|
+
- spec/tres_delta/gateway_spec.rb
|
99
|
+
- spec/tres_delta/vault_spec.rb
|
100
|
+
- tres_delta.gemspec
|
101
|
+
homepage: ''
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.1.11
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: A Ruby client for ThreeDelta's credit card vault and payment gateway.
|
125
|
+
test_files:
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
- spec/tres_delta/client_spec.rb
|
128
|
+
- spec/tres_delta/customer_spec.rb
|
129
|
+
- spec/tres_delta/gateway_spec.rb
|
130
|
+
- spec/tres_delta/vault_spec.rb
|