paytrace 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.vagrant/machines/default/virtualbox/action_provision +1 -0
- data/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/.vagrant/machines/default/virtualbox/id +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +19 -0
- data/Vagrantfile +121 -0
- data/lib/paytrace/api/fields.rb +17 -0
- data/lib/paytrace/api/gateway.rb +21 -0
- data/lib/paytrace/api/request.rb +38 -0
- data/lib/paytrace/api/response.rb +23 -0
- data/lib/paytrace/configuration.rb +13 -0
- data/lib/paytrace/credit_card.rb +11 -0
- data/lib/paytrace/transaction.rb +36 -0
- data/lib/paytrace/version.rb +3 -0
- data/lib/paytrace.rb +11 -0
- data/paytrace.gemspec +26 -0
- data/test/paytrace/api/fields_spec.rb +17 -0
- data/test/paytrace/api/gateway_spec.rb +26 -0
- data/test/paytrace/api/request_spec.rb +47 -0
- data/test/paytrace/api/response_spec.rb +10 -0
- data/test/paytrace/configuration_spec.rb +21 -0
- data/test/paytrace/credit_card_spec.rb +14 -0
- data/test/paytrace/transaction_spec.rb +26 -0
- data/test/test_helper.rb +5 -0
- data/vagrant-bootstrap.sh +23 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 33236dbde03fce5f6851d0e56b1aa746f1ee5400
|
4
|
+
data.tar.gz: dee3b79ad21659a2fb3ea0f7bab826c78c7e51fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3cb06a3040b0d967ad67f6ff9a1a6753896337fa020ca8d9b2e967a4d03c8f8091eff4e3b126a686874890828c45b39ad584ad6f762f76af576431caa8dd1476
|
7
|
+
data.tar.gz: 59a277cf612ae4e2324612b8d89846795284cb5fed9bf93d0733587b5e47a6d3c61ff42df2f778d139b02329fe16894287737a0d87c5e512a6c38a525e7e4e4a
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
paytrace_ruby
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.0
|
@@ -0,0 +1 @@
|
|
1
|
+
1393536090
|
@@ -0,0 +1 @@
|
|
1
|
+
1393536080
|
@@ -0,0 +1 @@
|
|
1
|
+
a966b052-f49f-413f-a0a3-60539add62a1
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Trevor Redfern
|
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,37 @@
|
|
1
|
+
# PaytraceRuby
|
2
|
+
|
3
|
+
![Build Status](https://www.codeship.io/projects/611ffe60-f3ee-0130-0299-1a84c3740ef1/status)
|
4
|
+
|
5
|
+
This gem integrates with the PayTrace API. It provides functionality to the
|
6
|
+
publicly available functionality including:
|
7
|
+
|
8
|
+
* Processing Transactions
|
9
|
+
* Creating Customers
|
10
|
+
* Exporting Transaction or Customer Data
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'paytrace_ruby'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install paytrace_ruby
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
TODO: Write usage instructions here
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'paytrace/version'
|
4
|
+
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
t.libs << "lib/paytrace_ruby"
|
7
|
+
t.test_files = FileList['test/**/*_spec.rb']
|
8
|
+
t.verbose = true
|
9
|
+
end
|
10
|
+
|
11
|
+
task :build do
|
12
|
+
system "gem build paytrace.gemspec"
|
13
|
+
end
|
14
|
+
|
15
|
+
task :release => :build do
|
16
|
+
system "gem push paytrace-#{PayTrace::VERSION}"
|
17
|
+
end
|
18
|
+
|
19
|
+
task :default => :test
|
data/Vagrantfile
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
5
|
+
VAGRANTFILE_API_VERSION = "2"
|
6
|
+
|
7
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
8
|
+
# All Vagrant configuration is done here. The most common configuration
|
9
|
+
# options are documented and commented below. For a complete reference,
|
10
|
+
# please see the online documentation at vagrantup.com.
|
11
|
+
|
12
|
+
# Every Vagrant virtual environment requires a box to build off of.
|
13
|
+
config.vm.box = "precise64"
|
14
|
+
|
15
|
+
# The url from where the 'config.vm.box' box will be fetched if it
|
16
|
+
# doesn't already exist on the user's system.
|
17
|
+
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
|
18
|
+
|
19
|
+
# Create a forwarded port mapping which allows access to a specific port
|
20
|
+
# within the machine from a port on the host machine. In the example below,
|
21
|
+
# accessing "localhost:8080" will access port 80 on the guest machine.
|
22
|
+
# config.vm.network :forwarded_port, guest: 80, host: 8080
|
23
|
+
|
24
|
+
# Create a private network, which allows host-only access to the machine
|
25
|
+
# using a specific IP.
|
26
|
+
# config.vm.network :private_network, ip: "192.168.33.10"
|
27
|
+
|
28
|
+
# Create a public network, which generally matched to bridged network.
|
29
|
+
# Bridged networks make the machine appear as another physical device on
|
30
|
+
# your network.
|
31
|
+
# config.vm.network :public_network
|
32
|
+
|
33
|
+
# If true, then any SSH connections made will enable agent forwarding.
|
34
|
+
# Default value: false
|
35
|
+
# config.ssh.forward_agent = true
|
36
|
+
|
37
|
+
# Share an additional folder to the guest VM. The first argument is
|
38
|
+
# the path on the host to the actual folder. The second argument is
|
39
|
+
# the path on the guest to mount the folder. And the optional third
|
40
|
+
# argument is a set of non-required options.
|
41
|
+
# config.vm.synced_folder "../data", "/vagrant_data"
|
42
|
+
|
43
|
+
# Provider-specific configuration so you can fine-tune various
|
44
|
+
# backing providers for Vagrant. These expose provider-specific options.
|
45
|
+
# Example for VirtualBox:
|
46
|
+
#
|
47
|
+
config.vm.provider :virtualbox do |vb|
|
48
|
+
# # Don't boot with headless mode
|
49
|
+
# vb.gui = true
|
50
|
+
#
|
51
|
+
# # Use VBoxManage to customize the VM. For example to change memory:
|
52
|
+
# vb.customize ["modifyvm", :id, "--memory", "1024"]
|
53
|
+
vb.memory = 2048
|
54
|
+
end
|
55
|
+
#
|
56
|
+
# View the documentation for the provider you're using for more
|
57
|
+
# information on available options.
|
58
|
+
|
59
|
+
config.vm.provision :shell, :path => "vagrant-bootstrap.sh"
|
60
|
+
|
61
|
+
# Enable provisioning with Puppet stand alone. Puppet manifests
|
62
|
+
# are contained in a directory path relative to this Vagrantfile.
|
63
|
+
# You will need to create the manifests directory and a manifest in
|
64
|
+
# the file precise64.pp in the manifests_path directory.
|
65
|
+
#
|
66
|
+
# An example Puppet manifest to provision the message of the day:
|
67
|
+
#
|
68
|
+
# # group { "puppet":
|
69
|
+
# # ensure => "present",
|
70
|
+
# # }
|
71
|
+
# #
|
72
|
+
# # File { owner => 0, group => 0, mode => 0644 }
|
73
|
+
# #
|
74
|
+
# # file { '/etc/motd':
|
75
|
+
# # content => "Welcome to your Vagrant-built virtual machine!
|
76
|
+
# # Managed by Puppet.\n"
|
77
|
+
# # }
|
78
|
+
#
|
79
|
+
# config.vm.provision :puppet do |puppet|
|
80
|
+
# puppet.manifests_path = "manifests"
|
81
|
+
# puppet.manifest_file = "site.pp"
|
82
|
+
# end
|
83
|
+
|
84
|
+
# Enable provisioning with chef solo, specifying a cookbooks path, roles
|
85
|
+
# path, and data_bags path (all relative to this Vagrantfile), and adding
|
86
|
+
# some recipes and/or roles.
|
87
|
+
#
|
88
|
+
# config.vm.provision :chef_solo do |chef|
|
89
|
+
# chef.cookbooks_path = "../my-recipes/cookbooks"
|
90
|
+
# chef.roles_path = "../my-recipes/roles"
|
91
|
+
# chef.data_bags_path = "../my-recipes/data_bags"
|
92
|
+
# chef.add_recipe "mysql"
|
93
|
+
# chef.add_role "web"
|
94
|
+
#
|
95
|
+
# # You may also specify custom JSON attributes:
|
96
|
+
# chef.json = { :mysql_password => "foo" }
|
97
|
+
# end
|
98
|
+
|
99
|
+
# Enable provisioning with chef server, specifying the chef server URL,
|
100
|
+
# and the path to the validation key (relative to this Vagrantfile).
|
101
|
+
#
|
102
|
+
# The Opscode Platform uses HTTPS. Substitute your organization for
|
103
|
+
# ORGNAME in the URL and validation key.
|
104
|
+
#
|
105
|
+
# If you have your own Chef Server, use the appropriate URL, which may be
|
106
|
+
# HTTP instead of HTTPS depending on your configuration. Also change the
|
107
|
+
# validation key to validation.pem.
|
108
|
+
#
|
109
|
+
# config.vm.provision :chef_client do |chef|
|
110
|
+
# chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
|
111
|
+
# chef.validation_key_path = "ORGNAME-validator.pem"
|
112
|
+
# end
|
113
|
+
#
|
114
|
+
# If you're using the Opscode platform, your validator client is
|
115
|
+
# ORGNAME-validator, replacing ORGNAME with your organization name.
|
116
|
+
#
|
117
|
+
# If you have your own Chef Server, the default validation client name is
|
118
|
+
# chef-validator, unless you changed the configuration.
|
119
|
+
#
|
120
|
+
# chef.validation_client_name = "ORGNAME-validator"
|
121
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PayTrace
|
2
|
+
module API
|
3
|
+
def self.fields
|
4
|
+
{
|
5
|
+
amount: "AMOUNT",
|
6
|
+
card_number: "CC",
|
7
|
+
expiration_year: "EXPYR",
|
8
|
+
expiration_month: "EXPMNTH",
|
9
|
+
method: "METHOD",
|
10
|
+
password: "PSWD",
|
11
|
+
terms: "TERMS",
|
12
|
+
transaction_type: "TRANXTYPE",
|
13
|
+
user_name: "UN",
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'paytrace/api/response'
|
3
|
+
|
4
|
+
module PayTrace
|
5
|
+
module API
|
6
|
+
class Gateway
|
7
|
+
DOMAIN = "paytrace.com"
|
8
|
+
API_ROOT = "api/default.pay"
|
9
|
+
URL = "https://#{DOMAIN}/#{API_ROOT}"
|
10
|
+
|
11
|
+
def initialize(connection: Faraday.new)
|
12
|
+
@connection = connection
|
13
|
+
end
|
14
|
+
|
15
|
+
def send_request(request)
|
16
|
+
res = @connection.post URL, parmlist: request.to_parms_string
|
17
|
+
PayTrace::API::Response.new(res.body)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module PayTrace
|
2
|
+
module API
|
3
|
+
class Request
|
4
|
+
TRANSACTION_METHOD = "PROCESSTRANX"
|
5
|
+
attr_reader :params, :field_delim, :value_delim
|
6
|
+
|
7
|
+
def initialize(transaction: nil)
|
8
|
+
@field_delim = "|"
|
9
|
+
@value_delim = "~"
|
10
|
+
|
11
|
+
@params= {
|
12
|
+
user_name: PayTrace.configuration.user_name,
|
13
|
+
password: PayTrace.configuration.password,
|
14
|
+
terms: "Y"
|
15
|
+
}
|
16
|
+
|
17
|
+
add_transaction(transaction) if transaction
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_parms_string()
|
21
|
+
@params.map do |k,v|
|
22
|
+
"#{PayTrace::API.fields.fetch(k)}#{@value_delim}#{v}"
|
23
|
+
end.join(@field_delim) << "|"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def add_transaction(t)
|
28
|
+
@params[:card_number] = t.credit_card.card_number
|
29
|
+
@params[:expiration_month] = t.credit_card.expiration_month
|
30
|
+
@params[:expiration_year] = t.credit_card.expiration_year
|
31
|
+
@params[:transaction_type] = t.type
|
32
|
+
@params[:method] = TRANSACTION_METHOD
|
33
|
+
@params[:amount] = t.amount
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PayTrace
|
2
|
+
module API
|
3
|
+
class Response
|
4
|
+
attr_reader :values
|
5
|
+
|
6
|
+
def initialize(response_string)
|
7
|
+
@field_delim = "|"
|
8
|
+
@value_delim = "~"
|
9
|
+
@values = {}
|
10
|
+
|
11
|
+
pairs = response_string.split(@field_delim)
|
12
|
+
pairs.each do |p|
|
13
|
+
k,v = p.split(@value_delim)
|
14
|
+
@values[k] = v
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def response_code
|
19
|
+
@values["RESPONSE"]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module PayTrace
|
2
|
+
class CreditCard
|
3
|
+
attr_accessor :card_number, :expiration_month, :expiration_year
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
@card_number = options[:card_number]
|
7
|
+
@expiration_month = options[:expiration_month]
|
8
|
+
@expiration_year = options[:expiration_year]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'paytrace/api/request'
|
2
|
+
require 'paytrace/api/gateway'
|
3
|
+
|
4
|
+
module PayTrace
|
5
|
+
module TransactionOperations
|
6
|
+
def sale(amount: nil, credit_card: nil, options: {})
|
7
|
+
t = Transaction.new(amount: amount,
|
8
|
+
credit_card: credit_card,
|
9
|
+
type: TransactionTypes::SALE)
|
10
|
+
request = PayTrace::API::Request.new(transaction: t)
|
11
|
+
gateway = PayTrace::API::Gateway.new
|
12
|
+
t.response = gateway.send_request(request)
|
13
|
+
t
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Transaction
|
18
|
+
class << self
|
19
|
+
include TransactionOperations
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :amount, :credit_card, :type
|
23
|
+
attr_accessor :response
|
24
|
+
|
25
|
+
def initialize(amount: nil, credit_card: nil, type: nil)
|
26
|
+
@amount = amount
|
27
|
+
@credit_card = CreditCard.new(credit_card)
|
28
|
+
@type = type
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
module TransactionTypes
|
34
|
+
SALE = "SALE"
|
35
|
+
end
|
36
|
+
end
|
data/lib/paytrace.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "paytrace/version"
|
2
|
+
require "paytrace/configuration"
|
3
|
+
require "paytrace/credit_card"
|
4
|
+
require "paytrace/transaction"
|
5
|
+
require 'paytrace/api/fields'
|
6
|
+
require 'paytrace/api/gateway'
|
7
|
+
require 'paytrace/api/request'
|
8
|
+
require 'paytrace/api/response'
|
9
|
+
|
10
|
+
module PayTrace
|
11
|
+
end
|
data/paytrace.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 'paytrace/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "paytrace"
|
8
|
+
spec.version = PayTrace::VERSION
|
9
|
+
spec.authors = ["Trevor Redfern"]
|
10
|
+
spec.email = ["trevor@paytrace.com"]
|
11
|
+
spec.description = %q{Integration with PayTrace Payment Gateway}
|
12
|
+
spec.summary = %q{Integration providing access to the transaction processing API for PayTrace}
|
13
|
+
spec.homepage = "http://github.com/PayTrace/paytrace_ruby"
|
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_dependency "faraday"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "mocha"
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../test_helper.rb')
|
2
|
+
require 'paytrace/api/fields'
|
3
|
+
|
4
|
+
|
5
|
+
describe PayTrace::API do
|
6
|
+
it "maps param list into paytrace url values" do
|
7
|
+
PayTrace::API.fields[:user_name].must_equal "UN"
|
8
|
+
PayTrace::API.fields[:password].must_equal "PSWD"
|
9
|
+
PayTrace::API.fields[:terms].must_equal "TERMS"
|
10
|
+
PayTrace::API.fields[:card_number].must_equal "CC"
|
11
|
+
PayTrace::API.fields[:expiration_year].must_equal "EXPYR"
|
12
|
+
PayTrace::API.fields[:expiration_month].must_equal "EXPMNTH"
|
13
|
+
PayTrace::API.fields[:method].must_equal "METHOD"
|
14
|
+
PayTrace::API.fields[:transaction_type].must_equal "TRANXTYPE"
|
15
|
+
PayTrace::API.fields[:amount].must_equal "AMOUNT"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../test_helper.rb')
|
2
|
+
require 'paytrace/api/gateway'
|
3
|
+
|
4
|
+
describe PayTrace::API::Gateway do
|
5
|
+
it "converts a request into a URL to the api specifying the user name and password from configuration" do
|
6
|
+
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
7
|
+
stub.post ("https://paytrace.com/api/default.pay") {[ 200, {}, 'foo' ]}
|
8
|
+
end
|
9
|
+
|
10
|
+
test = Faraday.new do |builder|
|
11
|
+
builder.adapter :test , stubs
|
12
|
+
end
|
13
|
+
|
14
|
+
request = mock()
|
15
|
+
request.stubs(:to_parms_string).returns("foo")
|
16
|
+
|
17
|
+
response = mock()
|
18
|
+
PayTrace::API::Response.stubs(:new).returns(response)
|
19
|
+
|
20
|
+
gateway = PayTrace::API::Gateway.new(connection: test)
|
21
|
+
r = gateway.send_request request
|
22
|
+
|
23
|
+
stubs.verify_stubbed_calls
|
24
|
+
r.must_equal response
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../test_helper.rb')
|
2
|
+
require 'paytrace/api/request'
|
3
|
+
|
4
|
+
describe PayTrace::API::Request do
|
5
|
+
before do
|
6
|
+
PayTrace.configure do |config|
|
7
|
+
config.user_name = "test"
|
8
|
+
config.password = "test"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "sets the user name, password, and terms parameters from the configuration file" do
|
13
|
+
#override to validate
|
14
|
+
PayTrace.configure do |config|
|
15
|
+
config.user_name = "request_test"
|
16
|
+
config.password = "request_password"
|
17
|
+
end
|
18
|
+
|
19
|
+
r = PayTrace::API::Request.new
|
20
|
+
r.params[:user_name].must_equal "request_test"
|
21
|
+
r.params[:password].must_equal "request_password"
|
22
|
+
r.params[:terms].must_equal "Y"
|
23
|
+
to_url = r.to_parms_string
|
24
|
+
to_url.must_equal "UN~request_test|PSWD~request_password|TERMS~Y|"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "can add a transaction to its param list" do
|
28
|
+
t = PayTrace::Transaction.new(amount: "23.12",
|
29
|
+
credit_card: {
|
30
|
+
card_number: "1234123412341234",
|
31
|
+
expiration_year: 24,
|
32
|
+
expiration_month: 10 },
|
33
|
+
type: PayTrace::TransactionTypes::SALE)
|
34
|
+
r = PayTrace::API::Request.new(transaction: t)
|
35
|
+
|
36
|
+
r.params[:card_number].must_equal "1234123412341234"
|
37
|
+
r.params[:expiration_month].must_equal 10
|
38
|
+
r.params[:expiration_year].must_equal 24
|
39
|
+
r.params[:transaction_type].must_equal "SALE"
|
40
|
+
r.params[:method].must_equal "PROCESSTRANX"
|
41
|
+
r.params[:amount].must_equal "23.12"
|
42
|
+
|
43
|
+
url = r.to_parms_string
|
44
|
+
url.must_equal "UN~test|PSWD~test|TERMS~Y|CC~1234123412341234|EXPMNTH~10|EXPYR~24|TRANXTYPE~SALE|METHOD~PROCESSTRANX|AMOUNT~23.12|"
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../test_helper.rb')
|
2
|
+
require 'paytrace/api/response'
|
3
|
+
|
4
|
+
describe PayTrace::API::Response do
|
5
|
+
it "parses a successful transaction response" do
|
6
|
+
from_server = "RESPONSE~101. Your transaction was successfully approved.|TRANSACTIONID~93|APPCODE~TAS671|APPMSG~APPROVAL TAS671 - Approved and completed|AVSRESPONSE~0|CSCRESPONSE~|"
|
7
|
+
response = PayTrace::API::Response.new(from_server)
|
8
|
+
response.response_code.must_equal "101. Your transaction was successfully approved."
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../test_helper.rb')
|
2
|
+
|
3
|
+
describe PayTrace::Configuration do
|
4
|
+
it "grants you access to the config through the module" do
|
5
|
+
c = PayTrace.configuration
|
6
|
+
c.must_be_instance_of(PayTrace::Configuration)
|
7
|
+
|
8
|
+
#Also, it should keep returning the same config
|
9
|
+
c.must_equal(PayTrace.configuration)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "lets you configure it by passing in blocks" do
|
13
|
+
PayTrace.configure do |c|
|
14
|
+
c.user_name = "demo"
|
15
|
+
c.password = "demo"
|
16
|
+
end
|
17
|
+
|
18
|
+
PayTrace.configuration.user_name.must_equal "demo"
|
19
|
+
PayTrace.configuration.password.must_equal "demo"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../test_helper.rb')
|
2
|
+
|
3
|
+
describe PayTrace::CreditCard do
|
4
|
+
it "can be initialized with nothing" do
|
5
|
+
cc = PayTrace::CreditCard.new
|
6
|
+
cc.card_number.must_be_nil
|
7
|
+
end
|
8
|
+
it "can be initialized from a card number and expiration date" do
|
9
|
+
cc = PayTrace::CreditCard.new(:card_number => "5454545454545454", :expiration_month => 10, :expiration_year => 24)
|
10
|
+
cc.card_number.must_equal "5454545454545454"
|
11
|
+
cc.expiration_month.must_equal 10
|
12
|
+
cc.expiration_year.must_equal 24
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../test_helper.rb')
|
2
|
+
|
3
|
+
describe PayTrace::Transaction do
|
4
|
+
it "can charge sales to a credit card" do
|
5
|
+
response = mock()
|
6
|
+
PayTrace::API::Gateway.any_instance.expects(:send_request).returns(response)
|
7
|
+
|
8
|
+
t = PayTrace::Transaction.sale(
|
9
|
+
amount: "1242.32",
|
10
|
+
credit_card: {
|
11
|
+
card_number: "1234123412341234",
|
12
|
+
expiration_month: 10,
|
13
|
+
expiration_year: 24
|
14
|
+
})
|
15
|
+
|
16
|
+
#Transaction is properly configured
|
17
|
+
t.amount.must_equal "1242.32"
|
18
|
+
t.type.must_equal PayTrace::TransactionTypes::SALE
|
19
|
+
|
20
|
+
#Sets up a card
|
21
|
+
t.credit_card.card_number.must_equal "1234123412341234"
|
22
|
+
t.credit_card.expiration_month.must_equal 10
|
23
|
+
t.credit_card.expiration_year.must_equal 24
|
24
|
+
t.response.must_equal response
|
25
|
+
end
|
26
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
apt-get update
|
4
|
+
apt-get install -y git rake ruby-bundler curl tmux
|
5
|
+
|
6
|
+
# Get newest RVM
|
7
|
+
\curl -sSL https://get.rvm.io | bash
|
8
|
+
|
9
|
+
# Put user vagrant in the rvm group
|
10
|
+
usermod -a -G rvm vagrant
|
11
|
+
|
12
|
+
# Install the version of Ruby we use
|
13
|
+
/usr/local/rvm/bin/rvm install 2.1.0
|
14
|
+
|
15
|
+
su - vagrant <<END_OF_COMMANDS
|
16
|
+
# Set up the system from the main shared folder
|
17
|
+
cd /vagrant
|
18
|
+
|
19
|
+
# Make sure the latest version of bundler is installed
|
20
|
+
gem update bundler
|
21
|
+
|
22
|
+
bundle install
|
23
|
+
END_OF_COMMANDS
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paytrace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Trevor Redfern
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mocha
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Integration with PayTrace Payment Gateway
|
70
|
+
email:
|
71
|
+
- trevor@paytrace.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-gemset"
|
78
|
+
- ".ruby-version"
|
79
|
+
- ".vagrant/machines/default/virtualbox/action_provision"
|
80
|
+
- ".vagrant/machines/default/virtualbox/action_set_name"
|
81
|
+
- ".vagrant/machines/default/virtualbox/id"
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- Vagrantfile
|
87
|
+
- lib/paytrace.rb
|
88
|
+
- lib/paytrace/api/fields.rb
|
89
|
+
- lib/paytrace/api/gateway.rb
|
90
|
+
- lib/paytrace/api/request.rb
|
91
|
+
- lib/paytrace/api/response.rb
|
92
|
+
- lib/paytrace/configuration.rb
|
93
|
+
- lib/paytrace/credit_card.rb
|
94
|
+
- lib/paytrace/transaction.rb
|
95
|
+
- lib/paytrace/version.rb
|
96
|
+
- paytrace.gemspec
|
97
|
+
- test/paytrace/api/fields_spec.rb
|
98
|
+
- test/paytrace/api/gateway_spec.rb
|
99
|
+
- test/paytrace/api/request_spec.rb
|
100
|
+
- test/paytrace/api/response_spec.rb
|
101
|
+
- test/paytrace/configuration_spec.rb
|
102
|
+
- test/paytrace/credit_card_spec.rb
|
103
|
+
- test/paytrace/transaction_spec.rb
|
104
|
+
- test/test_helper.rb
|
105
|
+
- vagrant-bootstrap.sh
|
106
|
+
homepage: http://github.com/PayTrace/paytrace_ruby
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.2.1
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Integration providing access to the transaction processing API for PayTrace
|
130
|
+
test_files:
|
131
|
+
- test/paytrace/api/fields_spec.rb
|
132
|
+
- test/paytrace/api/gateway_spec.rb
|
133
|
+
- test/paytrace/api/request_spec.rb
|
134
|
+
- test/paytrace/api/response_spec.rb
|
135
|
+
- test/paytrace/configuration_spec.rb
|
136
|
+
- test/paytrace/credit_card_spec.rb
|
137
|
+
- test/paytrace/transaction_spec.rb
|
138
|
+
- test/test_helper.rb
|