pin_payment 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +18 -0
- data/LICENSE +20 -0
- data/README.md +93 -0
- data/Rakefile +9 -0
- data/lib/pin_payment.rb +36 -0
- data/lib/pin_payment/base.rb +43 -0
- data/lib/pin_payment/charge.rb +30 -0
- data/lib/pin_payment/customer.rb +33 -0
- data/lib/pin_payment/error.rb +25 -0
- data/lib/pin_payment/refund.rb +32 -0
- data/lib/pin_payment/version.rb +8 -0
- data/pin_payment.gemspec +24 -0
- data/test/fixtures/responses.yml +15 -0
- data/test/test_helper.rb +11 -0
- data/test/test_pin_charge.rb +20 -0
- data/test/test_pin_customer.rb +40 -0
- data/test/test_pin_refund.rb +31 -0
- data/test/test_pin_setup.rb +21 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0c7b070b4634a8b7e1db258cf2453aed51f23393
|
4
|
+
data.tar.gz: 25fb4b21844ee2142355082d11ea250beea9fec0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df77eb656111fea702bf69ee97840b97cfd4e39f90663a9045f4e6c4b93ec1695523d764453630ef8fa213406110f3744ff29073e2ee0bf2212d677fdf66f628
|
7
|
+
data.tar.gz: e1d6ae83373cf53c7f9ef981496eca10cb97e5e447dbc510fcb4fba6850156f277c1abae798ca155b492768cdc87705420bcb0d501336a7eb1a5411dc0db17e9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# PinPayment
|
2
|
+
|
3
|
+
Ruby interface to the http://pin.net.au/ API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Using bundler you can add the gem to your Gemfile.
|
8
|
+
|
9
|
+
gem 'pin_payment'
|
10
|
+
|
11
|
+
Or you can clone the repo and build them gem yourself:
|
12
|
+
|
13
|
+
bundle install --path gems
|
14
|
+
bundle exec rake build
|
15
|
+
gem install pkg/pin*.gem
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
First you will need to set your `public_key`, `secret_key`, and the `api_url`.
|
20
|
+
These can be found on your pin.net.au dashboard (under the "Account" section).
|
21
|
+
If you're using rails, this is best done in an initializer such as
|
22
|
+
`config/initializers/pin_payment.rb`, and you will need different keys for different
|
23
|
+
environments, e.g. wrap them around `if Rails.env.development?`.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
PinPayment.public_key = 'super nintendo chalmers'
|
27
|
+
PinPayment.secret_key = 'purple monkey dishwasher'
|
28
|
+
PinPayment.api_url = 'http://api.pin.net.au' # Live endpoint, the default is the test endpoint
|
29
|
+
```
|
30
|
+
|
31
|
+
Creating the customer on pin.net.au is only required if you want to bill the
|
32
|
+
customer in future (e.g. recurring billing, where writing the background
|
33
|
+
task is up to you), if you are only doing a single transaction, this step is
|
34
|
+
not required (but recommended).
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
customer = PinPayment::Customer.create(email: 'foo@example.com', card_token: params[:card_token])
|
38
|
+
```
|
39
|
+
|
40
|
+
The important information from the returned object is `customer.token`. You
|
41
|
+
will need this for future billing. Store it in your own application
|
42
|
+
somewhere.
|
43
|
+
|
44
|
+
Now you can create charges.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
charge = PinPayment::Charge.create(
|
48
|
+
customer_token: customer.token, # you can optionally pass a card_token instead
|
49
|
+
email: customer.email,
|
50
|
+
amount: 1000,
|
51
|
+
currency: 'USD',
|
52
|
+
description: 'Widgets',
|
53
|
+
ip_address: request.ip
|
54
|
+
)
|
55
|
+
|
56
|
+
if charge.success?
|
57
|
+
# You would now store charge.token as a reference for this payment
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
## TODO
|
62
|
+
|
63
|
+
* `PinPayment::Card` is non existent. I haven't had a use for it myself as yet, it
|
64
|
+
would be easy to build and will do so if I ever see the need. But as per the
|
65
|
+
[guide in the documentation](https://pin.net.au/docs/guides/payment-forms),
|
66
|
+
for a web interface it is much better to have the `card_token` created in
|
67
|
+
the javascript and never have the responsibility of credit card info being
|
68
|
+
sent directly to your server.
|
69
|
+
* Neither of the models support being handed a `card` hash. The API supports
|
70
|
+
doing so, but as above, I've not yet had the need and have always had a
|
71
|
+
`card_token` handy to pass in.
|
72
|
+
|
73
|
+
## Testing
|
74
|
+
|
75
|
+
I'm just using the `fakeweb` gem at the moment with a bunch of pre-defined
|
76
|
+
responses that I know the API gives. We're not really here to test the output of
|
77
|
+
the API, I think we can safely assume it will always give the same output for
|
78
|
+
the same input, and I don't really want to spam their service every time someone
|
79
|
+
runs the test suite. Nor do I want to hard code my test API keys or expect every
|
80
|
+
developer to create a pin account. Suggestions on improvement here are welcome
|
81
|
+
though.
|
82
|
+
|
83
|
+
## Contributing
|
84
|
+
|
85
|
+
Fork it and send me pull requests. I'll happily merge it or tell you what I
|
86
|
+
think in no uncertain terms :-)
|
87
|
+
|
88
|
+
Do not bother sending me a pull request for ruby 1.8 support though. I will tell
|
89
|
+
you where to go, and it involves a bridge.
|
90
|
+
|
91
|
+
## Maintainer(s)
|
92
|
+
|
93
|
+
* Danial Pearce (git@tigris.id.au)
|
data/Rakefile
ADDED
data/lib/pin_payment.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'pin_payment/base'
|
2
|
+
require 'pin_payment/charge'
|
3
|
+
require 'pin_payment/customer'
|
4
|
+
require 'pin_payment/error'
|
5
|
+
require 'pin_payment/refund'
|
6
|
+
require 'pin_payment/version'
|
7
|
+
|
8
|
+
module PinPayment
|
9
|
+
@@api_url = 'https://test-api.pin.net.au'
|
10
|
+
@@secret_key = nil
|
11
|
+
@@public_key = nil
|
12
|
+
|
13
|
+
def self.api_url
|
14
|
+
@@api_url
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.api_url=(url)
|
18
|
+
@@api_url = url
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.secret_key
|
22
|
+
@@secret_key
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.secret_key=(key)
|
26
|
+
@@secret_key = key
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.public_key
|
30
|
+
@@public_key
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.public_key=(key)
|
34
|
+
@@public_key = key
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'pin_payment/error'
|
3
|
+
|
4
|
+
module PinPayment
|
5
|
+
class Base
|
6
|
+
|
7
|
+
protected
|
8
|
+
|
9
|
+
def self.post uri, options
|
10
|
+
fetch Net::HTTP::Post, uri, options
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.put uri, options
|
14
|
+
fetch Net::HTTP::Put, uri, options
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get uri, options
|
18
|
+
fetch Net::HTTP::Get, uri, options
|
19
|
+
end
|
20
|
+
|
21
|
+
# TODO: Accept card as a hash that would create the card at the same time as the charge
|
22
|
+
def self.fetch klass, uri, options
|
23
|
+
client = Net::HTTP.new(uri.host, uri.port)
|
24
|
+
client.use_ssl = true
|
25
|
+
client.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
26
|
+
response = client.request(
|
27
|
+
klass.new(uri.request_uri).tap do |http|
|
28
|
+
http.basic_auth(PinPayment.secret_key, '')
|
29
|
+
http['User-Agent'] = "#{self}/#{PinPayment::Version::STRING}"
|
30
|
+
http.set_form_data options
|
31
|
+
end
|
32
|
+
)
|
33
|
+
begin
|
34
|
+
response = JSON.parse(response.body)
|
35
|
+
rescue JSON::ParserError => e
|
36
|
+
raise Error::InvalidResponse.new(e.message)
|
37
|
+
end
|
38
|
+
raise(Error.create(response['error'], response['error_description'], response['messages'])) if response['error']
|
39
|
+
response['response']
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module PinPayment
|
2
|
+
class Charge < Base
|
3
|
+
attr_reader :token, :amount, :currency, :description, :email, :ip_address, :created_at, :card_token
|
4
|
+
|
5
|
+
def self.create options
|
6
|
+
response = self.post(
|
7
|
+
URI.parse(PinPayment.api_url).tap{|uri| uri.path = '/1/charges' },
|
8
|
+
options.select{|k| %w(amount currency description email ip_address card_token customer_token).include?(k.to_s) }
|
9
|
+
)
|
10
|
+
self.new.tap do |charge|
|
11
|
+
charge.instance_variable_set('@card_token', response['card']['token']) if response['card']
|
12
|
+
%w(token amount currency description email ip_address created_at error_message success).each do |key|
|
13
|
+
charge.instance_variable_set("@#{key}", response[key])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def refund!
|
19
|
+
Refund.create(charge_token: token)
|
20
|
+
end
|
21
|
+
|
22
|
+
def success?
|
23
|
+
@success == true
|
24
|
+
end
|
25
|
+
|
26
|
+
def errors
|
27
|
+
@error_message
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module PinPayment
|
2
|
+
class Customer < Base
|
3
|
+
attr_reader :token, :email, :created_at, :card_token
|
4
|
+
|
5
|
+
def self.create options
|
6
|
+
response = post(
|
7
|
+
URI.parse(PinPayment.api_url).tap{|uri| uri.path = '/1/customers' },
|
8
|
+
options.select{|k| %w(email card_token).include?(k.to_s) }
|
9
|
+
)
|
10
|
+
new.tap do |customer|
|
11
|
+
customer.instance_variable_set('@card_token', response['card']['token']) if response['card']
|
12
|
+
%w(token email created_at).each do |key|
|
13
|
+
customer.instance_variable_set("@#{key}", response[key])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.update options
|
19
|
+
# PUT /1/customers/cus_XZg1ULpWaROQCOT5PdwLkQ
|
20
|
+
response = put(
|
21
|
+
URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/customers/#{options[:token] || options['token']}" },
|
22
|
+
options.select{|k| %w(email card_token).include?(k.to_s) }
|
23
|
+
)
|
24
|
+
new.tap do |customer|
|
25
|
+
customer.instance_variable_set('@card_token', response['card']['token']) if response['card']
|
26
|
+
%w(token email created_at).each do |key|
|
27
|
+
customer.instance_variable_set("@#{key}", response[key])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module PinPayment
|
2
|
+
class Error < Exception
|
3
|
+
|
4
|
+
def self.create type, description, messages = nil
|
5
|
+
klass = case type
|
6
|
+
when 'token_already_used'; TokenAlreadyUsed
|
7
|
+
when 'invalid_resource'; InvalidResource
|
8
|
+
when 'resource_not_found'; ResourceNotFound
|
9
|
+
else self
|
10
|
+
end
|
11
|
+
if messages.is_a?(Array)
|
12
|
+
description = description + ' ' + messages.map{|x| "(#{x['message']})" }.join(' & ')
|
13
|
+
elsif messages.is_a?(Hash)
|
14
|
+
description = description + ' ' + messages.values.flatten.map{|x| "(#{x})" }.join(' & ')
|
15
|
+
end
|
16
|
+
klass.new(description)
|
17
|
+
end
|
18
|
+
|
19
|
+
class InvalidResponse < Error; end
|
20
|
+
class InvalidResource < Error; end
|
21
|
+
class ResourceNotFound < Error; end
|
22
|
+
class TokenAlreadyUsed < Error; end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module PinPayment
|
2
|
+
class Refund < Base
|
3
|
+
attr_reader :token, :amount, :currency, :charge_token, :created_at
|
4
|
+
|
5
|
+
def self.create options
|
6
|
+
response = self.post(
|
7
|
+
URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/charges/#{options[:charge_token] || options['charge_token']}/refunds" },
|
8
|
+
{}
|
9
|
+
)
|
10
|
+
self.new.tap do |charge|
|
11
|
+
%w(token amount currency created_at error_message status_message).each do |key|
|
12
|
+
charge.instance_variable_set("@#{key}", response[key])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# TODO: API documentation only shows success as being "null" in the JSON
|
18
|
+
# response, so not sure this is possible. All my refunds on the test site
|
19
|
+
# end up in a "Pending" state so not entirely sure on this one.
|
20
|
+
def success?
|
21
|
+
@success == true
|
22
|
+
end
|
23
|
+
|
24
|
+
def status
|
25
|
+
@status_message
|
26
|
+
end
|
27
|
+
|
28
|
+
def errors
|
29
|
+
@error_message
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/pin_payment.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
2
|
+
|
3
|
+
require 'pin_payment/version'
|
4
|
+
|
5
|
+
spec = Gem::Specification.new do |s|
|
6
|
+
s.name = 'pin_payment'
|
7
|
+
s.version = PinPayment::Version::STRING
|
8
|
+
s.summary = 'Ruby bindings for the Pin API'
|
9
|
+
s.description = 'Pin is the easiest way to accept payments online. See https://pin.net.au/ for details.'
|
10
|
+
s.authors = ['Danial Pearce']
|
11
|
+
s.email = ['git@tigris.id.au']
|
12
|
+
s.licenses = ['MIT']
|
13
|
+
s.homepage = 'https://github.com/tigris/pin_payment'
|
14
|
+
|
15
|
+
s.add_development_dependency('fakeweb')
|
16
|
+
s.add_development_dependency('rake')
|
17
|
+
|
18
|
+
s.required_ruby_version = '>= 1.9.2'
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- test/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ['lib']
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
charge:
|
3
|
+
token_already_used: '{"error":"token_already_used","error_description":"Token already used. Card tokens can only be used once, to create a charge or assign a card to a customer."}'
|
4
|
+
invalid_amount: '{"error":"invalid_resource","error_description":"One or more parameters were missing or invalid.","messages":[{"param":"amount","code":"amount_invalid","message":"Amount must be an integer"},{"param":"amount","code":"amount_invalid","message":"Amount must be more than 1 USD"}]}'
|
5
|
+
success: '{"response":{"token":"ch_BjGW-S6WUisI6mOgpDRimg","success":true,"amount":1000,"currency":"USD","description":"Widgets","email":"foo@example.com","ip_address":"127.0.0.1","created_at":"2013-06-12T23:55:38Z","status_message":"Success!","error_message":null,"card":{"token":"card_qMwnMfpG-olOhfJeyxmrcg","display_number":"XXXX-XXXX-XXXX-0000","scheme":"master","address_line1":"123 Main St","address_line2":"","address_city":"Melbourne","address_postcode":"3000","address_state":"Victoria","address_country":"Australia"},"transfer":[],"amount_refunded":0,"total_fees":null,"merchant_entitlement":null,"refund_pending":false}}'
|
6
|
+
update_customer:
|
7
|
+
blank_email: '{"error":"invalid_resource","error_description":"One or more parameters were missing or invalid.","messages":[{"param":"email","code":"email_invalid","message":"Email can''t be blank"}]}'
|
8
|
+
blank_token: '{"error":"resource_not_found","error_description":"No resource was found at this URL. See https://pin.net.au/docs/api for API documentation and a list of valid URLs."}'
|
9
|
+
success: '{"response":{"token":"cus__03Cn1lSk3offZ0IGkwpCg","email":"foo@example.com","created_at":"2013-06-12T10:08:30Z","card":{"token":"card_qMwnMfpG-olOhfJeyxmrcg","display_number":"XXXX-XXXX-XXXX-0000","scheme":"master","address_line1":"123 Main St","address_line2":"","address_city":"Melbourne","address_postcode":"3000","address_state":"Victoria","address_country":"Australia"}}}'
|
10
|
+
create_customer:
|
11
|
+
blank_email: '{"error":"invalid_resource","error_description":"One or more parameters were missing or invalid.","messages":[{"param":"email","code":"email_invalid","message":"Email can''t be blank"}]}'
|
12
|
+
success: '{"response":{"token":"cus__03Cn1lSk3offZ0IGkwpCg","email":"foo@example.com","created_at":"2013-06-12T10:08:30Z","card":{"token":"card_qMwnMfpG-olOhfJeyxmrcg","display_number":"XXXX-XXXX-XXXX-0000","scheme":"master","address_line1":"123 Main St","address_line2":"","address_city":"Melbourne","address_postcode":"3000","address_state":"Victoria","address_country":"Australia"}}}'
|
13
|
+
refund:
|
14
|
+
success: '{"response":{"token":"rf_wMYx5YHKaZAwQgj5rtNuTg","success":null,"amount":1000,"currency":"USD","charge":"ch_BjGW-S6WUisI6mOgpDRimg","created_at":"2013-06-25T03:16:33Z","error_message":null,"status_message":"Pending"}}'
|
15
|
+
duplicate: '{"error":"invalid_resource","error_description":"One or more parameters were missing or invalid.","messages":{"charge":["You have tried to refund more than the original charge"]}}'
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'fakeweb'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'pin_payment'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
def fixtures
|
7
|
+
return @fixtures if @fixtures
|
8
|
+
@fixtures = {}.tap do |f|
|
9
|
+
f['responses'] = YAML.load(File.read File.join(File.dirname(__FILE__), 'fixtures', 'responses.yml'))
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestPinCharge < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
FakeWeb.allow_net_connect = false
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_invalid_amount
|
9
|
+
FakeWeb.register_uri(:post, 'https://test-api.pin.net.au/1/charges', body: fixtures['responses']['charge']['invalid_amount'])
|
10
|
+
assert_raises PinPayment::Error::InvalidResource do
|
11
|
+
PinPayment::Charge.create(customer_token: 'cus__03Cn1lSk3offZ0IGkwpCg', amount: 10.0)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_successful_charge
|
16
|
+
FakeWeb.register_uri(:post, 'https://test-api.pin.net.au/1/charges', body: fixtures['responses']['charge']['success'])
|
17
|
+
charge = PinPayment::Charge.create(customer_token: 'cus__03Cn1lSk3offZ0IGkwpCg', amount: 1000)
|
18
|
+
assert_equal true, charge.success?
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestPinCustomer < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
FakeWeb.allow_net_connect = false
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_update_with_blank_email
|
9
|
+
FakeWeb.register_uri(:put, 'https://test-api.pin.net.au/1/customers/cus__03Cn1lSk3offZ0IGkwpCg', body: fixtures['responses']['update_customer']['blank_email'])
|
10
|
+
assert_raises PinPayment::Error::InvalidResource do
|
11
|
+
PinPayment::Customer.update(token: 'cus__03Cn1lSk3offZ0IGkwpCg', email: nil)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_update_with_blank_token
|
16
|
+
FakeWeb.register_uri(:put, 'https://test-api.pin.net.au/1/customers/', body: fixtures['responses']['update_customer']['blank_token'])
|
17
|
+
assert_raises PinPayment::Error::ResourceNotFound do
|
18
|
+
PinPayment::Customer.update(email: 'foo@example.com')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_create_with_blank_email
|
23
|
+
FakeWeb.register_uri(:post, 'https://test-api.pin.net.au/1/customers', body: fixtures['responses']['create_customer']['blank_email'])
|
24
|
+
assert_raises PinPayment::Error::InvalidResource do
|
25
|
+
PinPayment::Customer.create(email: nil)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_create_success
|
30
|
+
FakeWeb.register_uri(:post, 'https://test-api.pin.net.au/1/customers', body: fixtures['responses']['create_customer']['success'])
|
31
|
+
customer = PinPayment::Customer.create(email: 'foo@example.com')
|
32
|
+
assert_equal customer.token, 'cus__03Cn1lSk3offZ0IGkwpCg'
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_update_success
|
36
|
+
FakeWeb.register_uri(:put, 'https://test-api.pin.net.au/1/customers/cus__03Cn1lSk3offZ0IGkwpCg', body: fixtures['responses']['update_customer']['success'])
|
37
|
+
customer = PinPayment::Customer.update(token: 'cus__03Cn1lSk3offZ0IGkwpCg', email: 'foo@example.com')
|
38
|
+
assert_equal customer.token, 'cus__03Cn1lSk3offZ0IGkwpCg'
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestPinRefund < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
FakeWeb.allow_net_connect = false
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_duplicate_refund
|
9
|
+
token = 'ch_BjGW-S6WUisI6mOgpDRimg'
|
10
|
+
FakeWeb.register_uri(:post, "https://test-api.pin.net.au/1/charges/#{token}/refunds", body: fixtures['responses']['refund']['duplicate'])
|
11
|
+
assert_raises PinPayment::Error::InvalidResource do
|
12
|
+
PinPayment::Refund.create(charge_token: token)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_manual_refund
|
17
|
+
token = 'ch_BjGW-S6WUisI6mOgpDRimg'
|
18
|
+
FakeWeb.register_uri(:post, "https://test-api.pin.net.au/1/charges/#{token}/refunds", body: fixtures['responses']['refund']['success'])
|
19
|
+
refund = PinPayment::Refund.create(charge_token: token)
|
20
|
+
assert_equal 'Pending', refund.status
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_charge_refund
|
24
|
+
FakeWeb.register_uri(:post, 'https://test-api.pin.net.au/1/charges', body: fixtures['responses']['charge']['success'])
|
25
|
+
charge = PinPayment::Charge.create(customer_token: 'cus__03Cn1lSk3offZ0IGkwpCg', amount: 1000)
|
26
|
+
|
27
|
+
FakeWeb.register_uri(:post, "https://test-api.pin.net.au/1/charges/#{charge.token}/refunds", body: fixtures['responses']['refund']['success'])
|
28
|
+
refund = charge.refund!
|
29
|
+
assert_equal 'Pending', refund.status
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestPinSetup < MiniTest::Unit::TestCase
|
4
|
+
def test_setting_public_key
|
5
|
+
assert_equal nil, PinPayment.public_key
|
6
|
+
PinPayment.public_key = 'foo'
|
7
|
+
assert_equal 'foo', PinPayment.public_key
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_setting_secret_key
|
11
|
+
assert_equal nil, PinPayment.secret_key
|
12
|
+
PinPayment.secret_key = 'foo'
|
13
|
+
assert_equal 'foo', PinPayment.secret_key
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_api_url
|
17
|
+
assert_equal 'https://test-api.pin.net.au', PinPayment.api_url
|
18
|
+
PinPayment.api_url = 'foo'
|
19
|
+
assert_equal 'foo', PinPayment.api_url
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pin_payment
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danial Pearce
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fakeweb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Pin is the easiest way to accept payments online. See https://pin.net.au/
|
42
|
+
for details.
|
43
|
+
email:
|
44
|
+
- git@tigris.id.au
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/pin_payment.rb
|
56
|
+
- lib/pin_payment/base.rb
|
57
|
+
- lib/pin_payment/charge.rb
|
58
|
+
- lib/pin_payment/customer.rb
|
59
|
+
- lib/pin_payment/error.rb
|
60
|
+
- lib/pin_payment/refund.rb
|
61
|
+
- lib/pin_payment/version.rb
|
62
|
+
- pin_payment.gemspec
|
63
|
+
- test/fixtures/responses.yml
|
64
|
+
- test/test_helper.rb
|
65
|
+
- test/test_pin_charge.rb
|
66
|
+
- test/test_pin_customer.rb
|
67
|
+
- test/test_pin_refund.rb
|
68
|
+
- test/test_pin_setup.rb
|
69
|
+
homepage: https://github.com/tigris/pin_payment
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.9.2
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.0.2
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Ruby bindings for the Pin API
|
93
|
+
test_files:
|
94
|
+
- test/fixtures/responses.yml
|
95
|
+
- test/test_helper.rb
|
96
|
+
- test/test_pin_charge.rb
|
97
|
+
- test/test_pin_customer.rb
|
98
|
+
- test/test_pin_refund.rb
|
99
|
+
- test/test_pin_setup.rb
|