pin-payments 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +36 -0
- data/Gemfile +3 -0
- data/README.md +62 -0
- data/Rakefile +12 -0
- data/lib/pin-payments/base.rb +50 -0
- data/lib/pin-payments/card.rb +34 -0
- data/lib/pin-payments/charge.rb +30 -0
- data/lib/pin-payments/customer.rb +26 -0
- data/pin-payments.gemspec +26 -0
- data/test/stub_responses/cards.json +13 -0
- data/test/stub_responses/charges.json +33 -0
- data/test/stub_responses/customers.json +25 -0
- data/test/stub_responses/records/charge-ch_lfUYEBK14zotCTykezJkfg.json +26 -0
- data/test/stub_responses/records/customer-cus_XZg1ULpWaROQCOT5PdwLkQ.json +18 -0
- data/test/test_helper.rb +50 -0
- data/test/unit/cards_test.rb +16 -0
- data/test/unit/charges_test.rb +60 -0
- data/test/unit/customers_test.rb +33 -0
- metadata +30 -2
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
*.gem
|
21
|
+
*.rbc
|
22
|
+
.bundle
|
23
|
+
.config
|
24
|
+
.yardoc
|
25
|
+
Gemfile.lock
|
26
|
+
InstalledFiles
|
27
|
+
_yardoc
|
28
|
+
doc/
|
29
|
+
lib/bundler/man
|
30
|
+
spec/reports
|
31
|
+
test/tmp
|
32
|
+
test/version_tmp
|
33
|
+
tmp
|
34
|
+
|
35
|
+
## PROJECT::SPECIFIC
|
36
|
+
testing
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
## pin-payments
|
2
|
+
|
3
|
+
A wrapper for the [pin.net.au](https://pin.net.au/) [API](https://pin.net.au/docs/api). Available via [RubyGems](http://rubygems.org/gems/pin-payments):
|
4
|
+
|
5
|
+
gem install pin-payments
|
6
|
+
|
7
|
+
Extracted from [PayAus](http://www.payaus.com/). Still a bit rough around the edges.
|
8
|
+
|
9
|
+
MIT licensed, contributions are very welcome!
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
### Prerequisites
|
14
|
+
|
15
|
+
You'll need to create an account at [pin.net.au](https://pin.net.au/) first.
|
16
|
+
|
17
|
+
### Setup
|
18
|
+
|
19
|
+
Create an initializer, eg. `pin.rb`:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
Pin::Base.setup ENV['PIN_SECRET_KEY'], ENV['PIN_ENV']
|
23
|
+
```
|
24
|
+
|
25
|
+
You can get your secret key from Pin's [Your Account](https://dashboard.pin.net.au/account) page. The second argument should be "live" or "test" depending on which API you want to access.
|
26
|
+
|
27
|
+
### Usage
|
28
|
+
|
29
|
+
You'll probably want to create a form through which users can enter their details. [Pin's guide](https://pin.net.au/docs/guides/payment-forms) will step you through this.
|
30
|
+
|
31
|
+
Then, in your controller:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
def create
|
35
|
+
Pin::Charge.create email: 'alex@payaus.com', description: '1 month of service', amount: 19900,
|
36
|
+
currency: 'AUD', ip_address: params[:ip_address], card_token: params[:card_token]
|
37
|
+
redirect_to new_payment_path, notice: "Your credit card has been charged"
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
This will issue a once-off charge ([API](https://pin.net.au/docs/api/charges)). Alternatively, you may wish to create a customer. To do this, create a `Card` object first, then a corresponding `Customer` via the [API](https://pin.net.au/docs/api/customers).
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
card = Pin::Card.new number: '5520000000000000', expiry_month: '12', expiry_year: '2014', cvc: '123',
|
45
|
+
name: 'Roland Robot', address_line1: '42 Sevenoaks St', address_city: 'Lathlain', address_postcode: '6454', address_state: 'WA', address_country: 'Australia'
|
46
|
+
customer = Pin::Customer.create 'alex@payaus.com', card # this contacts the API
|
47
|
+
Pin::Charge.create email: 'alex@payaus.com', description: '1 month of service', amount: 19900,
|
48
|
+
currency: 'AUD', ip_address: '203.192.1.172', customer: customer # shorthand for customer_token: customer.token
|
49
|
+
```
|
50
|
+
|
51
|
+
You can view your customers in the [Pin dashboard](https://dashboard.pin.net.au/test/customers). This lets you charge customers regularly without asking for their credit card details each time.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
customers = Pin::Customer.all
|
55
|
+
customer = customers.find {|c| c.email == user.email} # assume user is the user you are trying to charge
|
56
|
+
Pin::Charge.create email: user.email, description: '1 month of service', amount: 19900, currency: 'AUD',
|
57
|
+
ip_address: user.ip_address, customer: customer
|
58
|
+
```
|
59
|
+
|
60
|
+
## Credits
|
61
|
+
|
62
|
+
https://github.com/ghiculescu/pin-payments/graphs/contributors
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
desc 'Default: run unit tests.'
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
desc 'Run unit tests.'
|
8
|
+
Rake::TestTask.new(:test) do |t|
|
9
|
+
t.libs << ['lib', 'test']
|
10
|
+
t.pattern = 'test/unit/**/*_test.rb'
|
11
|
+
t.verbose = true
|
12
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Pin
|
2
|
+
class Base
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
def initialize(attributes = {})
|
6
|
+
attributes.each do |name, value|
|
7
|
+
if name == 'card' # TODO: this should be generalised (has_one relationship i suppose)
|
8
|
+
self.card = Card.new value
|
9
|
+
else
|
10
|
+
send("#{name}=", value) if respond_to? "#{name}="
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.setup(key, mode = :live)
|
16
|
+
@@auth = {username: key, password: ''}
|
17
|
+
mode = mode.to_sym
|
18
|
+
uri = if mode == :test
|
19
|
+
"https://test-api.pin.net.au/1"
|
20
|
+
elsif mode == :live
|
21
|
+
"https://api.pin.net.au/1"
|
22
|
+
else
|
23
|
+
raise "Incorrect API mode! Must be :live or :test (leave blank for :live)."
|
24
|
+
end
|
25
|
+
base_uri uri
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
def self.authenticated_post(url, body)
|
30
|
+
post(url, body: body, basic_auth: @@auth)
|
31
|
+
end
|
32
|
+
def self.authenticated_get(url, query = nil)
|
33
|
+
get(url, query: query, basic_auth: @@auth)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.build_instance_from_response(response)
|
37
|
+
new(response.parsed_response['response'])
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.build_collection_from_response(response)
|
41
|
+
models = []
|
42
|
+
if response.code == 200
|
43
|
+
response.parsed_response['response'].each do |model|
|
44
|
+
models << new(model)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
models
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Pin
|
2
|
+
class Card < Base
|
3
|
+
attr_accessor :number, :expiry_month, :expiry_year, :cvc, :name, :address_line1,
|
4
|
+
:address_line2, :address_city, :address_postcode, :address_state,
|
5
|
+
:address_country,
|
6
|
+
:token, :display_number, :scheme
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
attributes.each {|name, value| send("#{name}=", value)}
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_hash
|
13
|
+
hash = {}
|
14
|
+
instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
|
15
|
+
hash
|
16
|
+
end
|
17
|
+
|
18
|
+
# options should be a hash with the following keys:
|
19
|
+
# :number, :expiry_month, :expiry_year, :cvc, :name, :address_line1,
|
20
|
+
# :address_city, :address_postcode, :address_state, :address_country
|
21
|
+
#
|
22
|
+
# it can also have the following optional keys:
|
23
|
+
# :address_line2
|
24
|
+
def self.create(options = {})
|
25
|
+
response = authenticated_post '/cards', options
|
26
|
+
if response.code == 201 # card created
|
27
|
+
build_instance_from_response(response)
|
28
|
+
else
|
29
|
+
# handle the error
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Pin
|
2
|
+
class Charge < Base
|
3
|
+
attr_accessor :token,
|
4
|
+
:email, :description, :amount, :currency, :ip_address,
|
5
|
+
:card, :card_token, :customer_token,
|
6
|
+
:amount_refunded, :total_fees, :merchant_entitlement, :refund_pending,
|
7
|
+
:success, :status_message, :error_message, :transfer, :created_at
|
8
|
+
|
9
|
+
# options should be a hash with the following params
|
10
|
+
# email, description, amount, currency, ip_address are mandatory
|
11
|
+
# identifier must be a hash, can take the forms
|
12
|
+
# {card: <Pin::Card>}
|
13
|
+
# {card_token: String<"...">}
|
14
|
+
# {customer_token: String<"...">}
|
15
|
+
# {customer: <Pin::Customer>}
|
16
|
+
# eg. {email: 'alex@payaus.com', description: '1 month of PayAus', amount: 19900, currency: 'AUD', ip_address: '203.192.1.172', customer_token: 'asdf'}
|
17
|
+
def self.create(options = {})
|
18
|
+
options[:customer_token] = options.delete(:customer).token unless options[:customer].nil?
|
19
|
+
build_instance_from_response(authenticated_post('/charges', options))
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.all # TODO: pagination
|
23
|
+
build_collection_from_response(authenticated_get('/charges'))
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.find(token)
|
27
|
+
build_instance_from_response(authenticated_get("/charges/#{token}"))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Pin
|
2
|
+
class Customer < Base
|
3
|
+
attr_accessor :email, :created_at, :token, :card
|
4
|
+
|
5
|
+
# email should be a string
|
6
|
+
# card_or_token can be a Pin::Card object
|
7
|
+
# or a card_token (as a string)
|
8
|
+
def self.create(email, card_or_token)
|
9
|
+
options = if card_or_token.respond_to?(:to_hash) # card
|
10
|
+
{card: card_or_token.to_hash}
|
11
|
+
else # token
|
12
|
+
{card_token: card_or_token}
|
13
|
+
end.merge(email: email)
|
14
|
+
|
15
|
+
build_instance_from_response(authenticated_post('/customers', options))
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.all # TODO: pagination
|
19
|
+
build_collection_from_response(authenticated_get('/customers'))
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.find(token)
|
23
|
+
build_instance_from_response(authenticated_get("/customers/#{token}"))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -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
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'pin-payments'
|
7
|
+
s.version = '0.0.3'
|
8
|
+
s.date = '2013-07-26'
|
9
|
+
s.summary = "Pin Payments API wrapper"
|
10
|
+
s.description = "A wrapper for the Pin Payments (https://pin.net.au/) API"
|
11
|
+
s.authors = ["Alex Ghiculescu"]
|
12
|
+
s.email = 'alexghiculescu@gmail.com'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split($/)
|
15
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.licenses = ["MIT"]
|
20
|
+
s.homepage = 'https://github.com/ghiculescu/pin-payments'
|
21
|
+
|
22
|
+
s.add_dependency "httparty"
|
23
|
+
|
24
|
+
s.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
s.add_development_dependency "webmock"
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
{
|
2
|
+
"response": {
|
3
|
+
"token": "card_nytGw7koRg23EEp9NTmz9w",
|
4
|
+
"display_number": "XXXX-XXXX-XXXX-0000",
|
5
|
+
"scheme": "master",
|
6
|
+
"address_line1": "42 Sevenoaks St",
|
7
|
+
"address_line2": null,
|
8
|
+
"address_city": "Lathlain",
|
9
|
+
"address_postcode": "6454",
|
10
|
+
"address_state": "WA",
|
11
|
+
"address_country": "Australia"
|
12
|
+
}
|
13
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
{
|
2
|
+
"response": [
|
3
|
+
{
|
4
|
+
"token": "ch_lfUYEBK14zotCTykezJkfg",
|
5
|
+
"success": true,
|
6
|
+
"amount": 400,
|
7
|
+
"currency": null,
|
8
|
+
"description": "test charge",
|
9
|
+
"email": "roland@pin.net.au",
|
10
|
+
"ip_address": "203.192.1.172",
|
11
|
+
"created_at": "2012-06-20T03:10:49Z",
|
12
|
+
"status_message": "Success!",
|
13
|
+
"error_message": null,
|
14
|
+
"card": {
|
15
|
+
"token": "card_nytGw7koRg23EEp9NTmz9w",
|
16
|
+
"display_number": "XXXX-XXXX-XXXX-0000",
|
17
|
+
"scheme": "master",
|
18
|
+
"address_line1": "42 Sevenoaks St",
|
19
|
+
"address_line2": null,
|
20
|
+
"address_city": "Lathlain",
|
21
|
+
"address_postcode": "6454",
|
22
|
+
"address_state": "WA",
|
23
|
+
"address_country": "Australia"
|
24
|
+
},
|
25
|
+
"transfer": null
|
26
|
+
}
|
27
|
+
],
|
28
|
+
"pagination": {
|
29
|
+
"current": 1,
|
30
|
+
"per_page": 25,
|
31
|
+
"count": 1
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"response": [
|
3
|
+
{
|
4
|
+
"token": "cus_XZg1ULpWaROQCOT5PdwLkQ",
|
5
|
+
"email": "roland@pin.net.au",
|
6
|
+
"created_at": "2012-06-22T06:27:33Z",
|
7
|
+
"card": {
|
8
|
+
"token": "card_nytGw7koRg23EEp9NTmz9w",
|
9
|
+
"display_number": "XXXX-XXXX-XXXX-0000",
|
10
|
+
"scheme": "master",
|
11
|
+
"address_line1": "42 Sevenoaks St",
|
12
|
+
"address_line2": null,
|
13
|
+
"address_city": "Lathlain",
|
14
|
+
"address_postcode": "6454",
|
15
|
+
"address_state": "WA",
|
16
|
+
"address_country": "Australia"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
],
|
20
|
+
"pagination": {
|
21
|
+
"current": 1,
|
22
|
+
"per_page": 25,
|
23
|
+
"count": 1
|
24
|
+
}
|
25
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"response": {
|
3
|
+
"token": "ch_lfUYEBK14zotCTykezJkfg",
|
4
|
+
"success": true,
|
5
|
+
"amount": 400,
|
6
|
+
"currency": null,
|
7
|
+
"description": "test charge",
|
8
|
+
"email": "roland@pin.net.au",
|
9
|
+
"ip_address": "203.192.1.172",
|
10
|
+
"created_at": "2012-06-20T03:10:49Z",
|
11
|
+
"status_message": "Success!",
|
12
|
+
"error_message": null,
|
13
|
+
"card": {
|
14
|
+
"token": "card_nytGw7koRg23EEp9NTmz9w",
|
15
|
+
"display_number": "XXXX-XXXX-XXXX-0000",
|
16
|
+
"scheme": "master",
|
17
|
+
"address_line1": "42 Sevenoaks St",
|
18
|
+
"address_line2": null,
|
19
|
+
"address_city": "Lathlain",
|
20
|
+
"address_postcode": "6454",
|
21
|
+
"address_state": "WA",
|
22
|
+
"address_country": "Australia"
|
23
|
+
},
|
24
|
+
"transfer": null
|
25
|
+
}
|
26
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"response": {
|
3
|
+
"token": "cus_XZg1ULpWaROQCOT5PdwLkQ",
|
4
|
+
"email": "roland@pin.net.au",
|
5
|
+
"created_at": "2012-06-22T06:27:33Z",
|
6
|
+
"card": {
|
7
|
+
"token": "card_nytGw7koRg23EEp9NTmz9w",
|
8
|
+
"display_number": "XXXX-XXXX-XXXX-0000",
|
9
|
+
"scheme": "master",
|
10
|
+
"address_line1": "42 Sevenoaks St",
|
11
|
+
"address_line2": null,
|
12
|
+
"address_city": "Lathlain",
|
13
|
+
"address_postcode": "6454",
|
14
|
+
"address_state": "WA",
|
15
|
+
"address_country": "Australia"
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require 'debugger'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'webmock/test_unit'
|
5
|
+
require 'active_support/inflector'
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + '/../lib/pin-payments.rb'
|
8
|
+
|
9
|
+
module TestHelper
|
10
|
+
|
11
|
+
SECRET_KEY = ENV["PIN_SECRET_KEY"] || "fake_key"
|
12
|
+
PIN_ENV = ENV["PIN_ENV"] || :test
|
13
|
+
|
14
|
+
Pin::Base.setup SECRET_KEY, PIN_ENV
|
15
|
+
|
16
|
+
def get_file(filename)
|
17
|
+
File.new(File.dirname(__FILE__) + "/stub_responses/" + filename)
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_record_json(type, token = nil)
|
21
|
+
if token.nil?
|
22
|
+
get_file("#{type}.json")
|
23
|
+
else
|
24
|
+
get_file("records/#{type}-#{token}.json")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def mock_get(model_name, do_each = true)
|
29
|
+
stub_request(:get, /#{model_name.downcase}$/).to_return(body: get_record_json(model_name.downcase.pluralize), status: 200, headers: {'Content-Type' => 'application/json; charset=utf-8'})
|
30
|
+
if do_each
|
31
|
+
Pin.const_get(model_name.singularize).all.each do |record|
|
32
|
+
stub_request(:get, /#{model_name.downcase}\/#{record.token}$/).to_return(body: get_record_json(model_name.downcase.singularize, record.token), status: 200, headers: {'Content-Type' => 'application/json; charset=utf-8'})
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def mock_post(model_name, do_each = true)
|
38
|
+
stub_request(:post, /#{model_name.downcase}$/).to_return(body: get_record_json(model_name.downcase.pluralize), status: 201, headers: {'Content-Type' => 'application/json; charset=utf-8'})
|
39
|
+
if do_each
|
40
|
+
Pin.const_get(model_name.singularize).all.each do |record|
|
41
|
+
stub_request(:post, /#{model_name.downcase}\/#{record.token}$/).to_return(body: get_record_json(model_name.downcase.singularize, record.token), status: 201, headers: {'Content-Type' => 'application/json; charset=utf-8'})
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def mock_api(model_name)
|
47
|
+
mock_get(model_name)
|
48
|
+
mock_post(model_name)
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CardsTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
mock_post('Cards', false)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_create
|
11
|
+
attributes = {number: '5520000000000000', expiry_month: '12', expiry_year: '2014', cvc: '123', name: 'Roland Robot', address_line1: '42 Sevenoaks St', address_city: 'Lathlain', address_postcode: '6454', address_state: 'WA', address_country: 'Australia'}
|
12
|
+
card = Pin::Card.create(attributes)
|
13
|
+
assert_not_nil card
|
14
|
+
assert_not_nil card.token
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ChargesTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
mock_post('Cards', false)
|
8
|
+
mock_api('Charges')
|
9
|
+
mock_api('Customers')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_get_all # for some reason `test "get all" do` wasn't working...
|
13
|
+
charges = Pin::Charge.all
|
14
|
+
assert_equal 1, charges.length
|
15
|
+
|
16
|
+
first = charges.first
|
17
|
+
charge = Pin::Charge.find(first.token)
|
18
|
+
assert_not_nil charge
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_create_charge_with_card
|
22
|
+
card = Pin::Card.new number: '5520000000000000', expiry_month: '12', expiry_year: '2014', cvc: '123', name: 'Roland Robot', address_line1: '42 Sevenoaks St', address_city: 'Lathlain', address_postcode: '6454', address_state: 'WA', address_country: 'Australia'
|
23
|
+
|
24
|
+
charge = Pin::Charge.create email: 'alex@payaus.com', description: '1 month of service', amount: 19900, currency: 'AUD', ip_address: '203.192.1.172',
|
25
|
+
card: card
|
26
|
+
assert_not_nil charge
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_create_charge_with_card_token
|
30
|
+
card = Pin::Card.create number: '5520000000000000', expiry_month: '12', expiry_year: '2014', cvc: '123', name: 'Roland Robot', address_line1: '42 Sevenoaks St', address_city: 'Lathlain', address_postcode: '6454', address_state: 'WA', address_country: 'Australia'
|
31
|
+
|
32
|
+
charge = Pin::Charge.create email: 'alex@payaus.com', description: '1 month of service', amount: 19900, currency: 'AUD', ip_address: '203.192.1.172',
|
33
|
+
card_token: card.token
|
34
|
+
assert_not_nil charge
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_create_charge_with_already_created_card
|
38
|
+
card = Pin::Card.create number: '5520000000000000', expiry_month: '12', expiry_year: '2014', cvc: '123', name: 'Roland Robot', address_line1: '42 Sevenoaks St', address_city: 'Lathlain', address_postcode: '6454', address_state: 'WA', address_country: 'Australia'
|
39
|
+
|
40
|
+
charge = Pin::Charge.create email: 'alex@payaus.com', description: '1 month of service', amount: 19900, currency: 'AUD', ip_address: '203.192.1.172',
|
41
|
+
card: card
|
42
|
+
assert_not_nil charge
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_create_charge_with_customer_token
|
46
|
+
customer = Pin::Customer.all.first
|
47
|
+
|
48
|
+
charge = Pin::Charge.create email: 'alex@payaus.com', description: '1 month of service', amount: 19900, currency: 'AUD', ip_address: '203.192.1.172',
|
49
|
+
customer_token: customer.token
|
50
|
+
assert_not_nil charge
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_create_charge_with_customer
|
54
|
+
customer = Pin::Customer.all.first
|
55
|
+
|
56
|
+
charge = Pin::Charge.create email: 'alex@payaus.com', description: '1 month of service', amount: 19900, currency: 'AUD', ip_address: '203.192.1.172',
|
57
|
+
customer: customer
|
58
|
+
assert_not_nil charge
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CustomersTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
mock_api('Customers')
|
8
|
+
mock_post('Cards', false)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_get_all # for some reason `test "get all" do` wasn't working...
|
12
|
+
customers = Pin::Customer.all
|
13
|
+
assert_equal 1, customers.length
|
14
|
+
|
15
|
+
first = customers.first
|
16
|
+
customer = Pin::Customer.find(first.token)
|
17
|
+
assert_not_nil customer
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_create_customer_with_card
|
21
|
+
card = Pin::Card.new number: '5520000000000000', expiry_month: '12', expiry_year: '2014', cvc: '123', name: 'Roland Robot', address_line1: '42 Sevenoaks St', address_city: 'Lathlain', address_postcode: '6454', address_state: 'WA', address_country: 'Australia'
|
22
|
+
|
23
|
+
customer = Pin::Customer.create('alex@payaus.com', card)
|
24
|
+
assert_not_nil customer
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_create_customer_with_token
|
28
|
+
card = Pin::Card.create number: '5520000000000000', expiry_month: '12', expiry_year: '2014', cvc: '123', name: 'Roland Robot', address_line1: '42 Sevenoaks St', address_city: 'Lathlain', address_postcode: '6454', address_state: 'WA', address_country: 'Australia'
|
29
|
+
|
30
|
+
customer = Pin::Customer.create('alex@payaus.com', card.token)
|
31
|
+
assert_not_nil customer
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pin-payments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -65,7 +65,26 @@ executables: []
|
|
65
65
|
extensions: []
|
66
66
|
extra_rdoc_files: []
|
67
67
|
files:
|
68
|
+
- .gitignore
|
69
|
+
- Gemfile
|
70
|
+
- Gemfile.lock
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
68
73
|
- lib/pin-payments.rb
|
74
|
+
- lib/pin-payments/base.rb
|
75
|
+
- lib/pin-payments/card.rb
|
76
|
+
- lib/pin-payments/charge.rb
|
77
|
+
- lib/pin-payments/customer.rb
|
78
|
+
- pin-payments.gemspec
|
79
|
+
- test/stub_responses/cards.json
|
80
|
+
- test/stub_responses/charges.json
|
81
|
+
- test/stub_responses/customers.json
|
82
|
+
- test/stub_responses/records/charge-ch_lfUYEBK14zotCTykezJkfg.json
|
83
|
+
- test/stub_responses/records/customer-cus_XZg1ULpWaROQCOT5PdwLkQ.json
|
84
|
+
- test/test_helper.rb
|
85
|
+
- test/unit/cards_test.rb
|
86
|
+
- test/unit/charges_test.rb
|
87
|
+
- test/unit/customers_test.rb
|
69
88
|
homepage: https://github.com/ghiculescu/pin-payments
|
70
89
|
licenses:
|
71
90
|
- MIT
|
@@ -91,4 +110,13 @@ rubygems_version: 1.8.25
|
|
91
110
|
signing_key:
|
92
111
|
specification_version: 3
|
93
112
|
summary: Pin Payments API wrapper
|
94
|
-
test_files:
|
113
|
+
test_files:
|
114
|
+
- test/stub_responses/cards.json
|
115
|
+
- test/stub_responses/charges.json
|
116
|
+
- test/stub_responses/customers.json
|
117
|
+
- test/stub_responses/records/charge-ch_lfUYEBK14zotCTykezJkfg.json
|
118
|
+
- test/stub_responses/records/customer-cus_XZg1ULpWaROQCOT5PdwLkQ.json
|
119
|
+
- test/test_helper.rb
|
120
|
+
- test/unit/cards_test.rb
|
121
|
+
- test/unit/charges_test.rb
|
122
|
+
- test/unit/customers_test.rb
|