pin_up 1.3.4 → 1.4.0
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 +5 -5
- data/.travis.yml +2 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +4 -9
- data/Gemfile.lock +74 -99
- data/README.md +155 -11
- data/VERSION +1 -1
- data/lib/pin_up.rb +3 -0
- data/lib/pin_up/pin_errors.rb +6 -0
- data/lib/pin_up/plan.rb +79 -0
- data/lib/pin_up/subscription.rb +80 -0
- data/lib/pin_up/webhook_endpoints.rb +45 -0
- data/pin_up.gemspec +48 -44
- data/spec/cards_spec.rb +14 -2
- data/spec/charges_spec.rb +57 -13
- data/spec/customers_spec.rb +52 -23
- data/spec/errors_spec.rb +294 -61
- data/spec/plan_spec.rb +189 -0
- data/spec/recipients_spec.rb +14 -9
- data/spec/refund_spec.rb +42 -8
- data/spec/spec_helper.rb +3 -4
- data/spec/subscription_spec.rb +201 -0
- data/spec/transfers_spec.rb +23 -17
- data/spec/webhook_endpoints_spec.rb +36 -0
- metadata +20 -27
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
data/lib/pin_up.rb
CHANGED
data/lib/pin_up/pin_errors.rb
CHANGED
@@ -18,6 +18,12 @@ module Pin
|
|
18
18
|
case response['error']
|
19
19
|
when 'cannot_delete_primary_card'
|
20
20
|
raise Pin::InvalidResource.new(response, response['error_description'])
|
21
|
+
when 'invalid_card'
|
22
|
+
raise Pin::InvalidResource.new(response, response['error_description'])
|
23
|
+
when 'invalid_state'
|
24
|
+
raise Pin::InvalidResource.new(response, response['error_description'])
|
25
|
+
when 'invalid_request'
|
26
|
+
raise Pin::InvalidResource.new(response, response['error_description'])
|
21
27
|
else
|
22
28
|
raise Pin::ChargeError.new(response)
|
23
29
|
end
|
data/lib/pin_up/plan.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
module Pin
|
2
|
+
##
|
3
|
+
# This class models Pins Plans API
|
4
|
+
class Plan < Base
|
5
|
+
##
|
6
|
+
# Lists all plans for your account
|
7
|
+
# args: page (Fixnum), pagination (Boolean)
|
8
|
+
# returns: a collection of customer objects
|
9
|
+
#
|
10
|
+
# if pagination is passed, access the response hash with [:response]
|
11
|
+
# and the pagination hash with [:pagination]
|
12
|
+
#
|
13
|
+
# https://www.pinpayments.com/developers/api-reference/plans
|
14
|
+
def self.all(page = nil, pagination = false)
|
15
|
+
build_collection_response(make_request(:get, {url: "plans?page=#{page}" } ), pagination)
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Create a plan given plan details
|
20
|
+
# args: options (Hash)
|
21
|
+
# returns: a plan object
|
22
|
+
# https://www.pinpayments.com/developers/api-reference/plans
|
23
|
+
def self.create(options = {})
|
24
|
+
build_response(make_request(:post, { url: 'plans', options: options }))
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Find a plan for your account given a token
|
29
|
+
# args: token (String)
|
30
|
+
# returns: a plan object
|
31
|
+
# https://www.pinpayments.com/developers/api-reference/plans#get-plan
|
32
|
+
def self.find(token)
|
33
|
+
build_response(make_request(:get, {url: "plans/#{token}" } ))
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Update a plan given a token
|
38
|
+
# args: token (String), options (Hash)
|
39
|
+
# returns: a plan object
|
40
|
+
# https://www.pinpayments.com/developers/api-reference/plans#put-plan
|
41
|
+
def self.update(token, options = {})
|
42
|
+
build_response(make_request(:put, { url: "plans/#{token}", options: options }))
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Delete a plan given a token
|
47
|
+
# args: token (String)
|
48
|
+
# returns: nil
|
49
|
+
# https://www.pinpayments.com/developers/api-reference/plans#delete-plan
|
50
|
+
def self.delete(token)
|
51
|
+
build_response(make_request(:delete, { url: "plans/#{token}" } ))
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# List Subscriptions associated with a plan given a token
|
56
|
+
# args: token (String)
|
57
|
+
# returns: nil
|
58
|
+
#
|
59
|
+
def self.subscriptions(token, page = nil, pagination = false)
|
60
|
+
build_collection_response(make_request(:get, { url: "plans/#{token}/subscriptions" } ), pagination)
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# Create a subscription for a plan given a customer_token OR a card_token
|
65
|
+
# args: customer_token (String), card (String) see docs.
|
66
|
+
# returns: a subscription object
|
67
|
+
#
|
68
|
+
def self.create_subscription(token, customer_token, card_token = nil)
|
69
|
+
options = if card_token
|
70
|
+
{ customer_token: customer_token,
|
71
|
+
card_token: card_token}
|
72
|
+
else
|
73
|
+
{ customer_token: customer_token }
|
74
|
+
end
|
75
|
+
|
76
|
+
build_response(make_request(:post, {url: "plans/#{token}/subscriptions", options: options} ))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Pin
|
2
|
+
##
|
3
|
+
# This class models Pins Subscription API
|
4
|
+
class Subscription < Base
|
5
|
+
##
|
6
|
+
# Lists all subscriptions for your account
|
7
|
+
# args: page (Fixnum), pagination (Boolean)
|
8
|
+
# returns: a collection of subscription objects
|
9
|
+
#
|
10
|
+
# if pagination is passed, access the response hash with [:response]
|
11
|
+
# and the pagination hash with [:pagination]
|
12
|
+
#
|
13
|
+
# https://www.pinpayments.com/developers/api-reference/subscriptions#get-subscriptions
|
14
|
+
def self.all(page = nil, pagination = false)
|
15
|
+
build_collection_response(make_request(:get, { url: "subscriptions?page=#{page}" }), pagination)
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Create a subscription given subscription details
|
20
|
+
# args: options (Hash)
|
21
|
+
# returns: a subscription object
|
22
|
+
# https://www.pinpayments.com/developers/api-reference/subscriptions#post-subscriptions
|
23
|
+
def self.create(options = {})
|
24
|
+
build_response(make_request(:post, { url: 'subscriptions', options: options }))
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Find a subscription for your account given a token
|
29
|
+
# args: token (String)
|
30
|
+
# returns: a subscription object
|
31
|
+
# https://www.pinpayments.com/developers/api-reference/subscriptions#get-subscription
|
32
|
+
def self.find(token)
|
33
|
+
build_response(make_request(:get, { url: "subscriptions/#{token}" }))
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Update a subscription for your account given a token
|
38
|
+
# and any of: email, card (hash),card_token
|
39
|
+
# args: token (String), options (Hash)
|
40
|
+
# returns: a subscription object
|
41
|
+
# https://pin.net.au/docs/api/subscriptions#put-subscription
|
42
|
+
# NB: When providing a card (hash), you need to specify
|
43
|
+
# the full list of details.
|
44
|
+
def self.update(token, card_token = nil)
|
45
|
+
options = unless card_token.empty?
|
46
|
+
{ card_token: card_token }
|
47
|
+
else
|
48
|
+
card_token
|
49
|
+
end
|
50
|
+
build_response(make_request(:put, { url: "subscriptions/#{token}", options: options }))
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# Delete (cancel) a subscription given a token
|
55
|
+
# args: token (String)
|
56
|
+
# returns: nil
|
57
|
+
# https://www.pinpayments.com/developers/api-reference/subscriptions#delete-subscription
|
58
|
+
def self.delete(token)
|
59
|
+
build_response(make_request(:delete, { url: "subscriptions/#{token}" }))
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Reactivate a subscription given a token
|
64
|
+
# args: token (String)
|
65
|
+
# returns: nil
|
66
|
+
# https://www.pinpayments.com/developers/api-reference/subscriptions#reactivate-subscription
|
67
|
+
def self.reactivate(token)
|
68
|
+
build_response(make_request(:put, { url: "subscriptions/#{token}/reactivate" }))
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
# Fetch all History for a subscription given a token
|
73
|
+
# args: token (String)
|
74
|
+
# returns: nil
|
75
|
+
# https://www.pinpayments.com/developers/api-reference/subscriptions#history-subscription
|
76
|
+
def self.history(token, page = nil, pagination = false)
|
77
|
+
build_collection_response(make_request(:get, { url: "subscriptions/#{token}/history?page=#{page}" }), pagination)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Pin
|
2
|
+
##
|
3
|
+
# This class models Pin's WebhookEndpoints API
|
4
|
+
class WebhookEndpoints < Base
|
5
|
+
##
|
6
|
+
# Lists all webhook endpoints for your account
|
7
|
+
# args: page (Fixnum), pagination (Boolean)
|
8
|
+
# returns: a collection of webhook endpoint objects
|
9
|
+
#
|
10
|
+
# if pagination is passed, access the response hash with [:response]
|
11
|
+
# and the pagination hash with [:pagination]
|
12
|
+
#
|
13
|
+
# https://pin.net.au/docs/api/webhook_endpoints#get-webhook_endpoints
|
14
|
+
def self.all(page = nil, pagination = false)
|
15
|
+
build_collection_response(make_request(:get, {url: "webhook_endpoints?page=#{page}" } ), pagination)
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# creates a webhook endpoint given a hash of options
|
20
|
+
# https://pin.net.au/docs/api/webhook_endpoints
|
21
|
+
# args: url (Hash)
|
22
|
+
# returns: webhook object
|
23
|
+
def self.create(options)
|
24
|
+
build_response(make_request(:post, { url: 'webhook_endpoints', options: options }))
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Find a webhook endpoint for your account given a token
|
29
|
+
# args: token (String)
|
30
|
+
# returns: a webhook endpoint object
|
31
|
+
# https://pin.net.au/docs/api/webhook_endpoints#get-webhook_endpoints
|
32
|
+
def self.find(token)
|
33
|
+
build_response(make_request(:get, {url: "webhook_endpoints/#{token}" } ))
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Delete a webhook endpoint for your account given a token
|
38
|
+
# args: token (String)
|
39
|
+
# returns: nil
|
40
|
+
# https://pin.net.au/docs/api/webhook_endpoints#delete-webhook_endpoints
|
41
|
+
def self.delete(token)
|
42
|
+
build_response(make_request(:delete, {url: "webhook_endpoints/#{token}" } ))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/pin_up.gemspec
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: pin_up 1.
|
5
|
+
# stub: pin_up 1.4.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
|
-
s.name = "pin_up"
|
9
|
-
s.version = "1.
|
8
|
+
s.name = "pin_up".freeze
|
9
|
+
s.version = "1.4.0"
|
10
10
|
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
-
s.require_paths = ["lib"]
|
13
|
-
s.authors = ["Daniel Nitsikopoulos"]
|
14
|
-
s.date = "
|
15
|
-
s.description = "A Ruby gem wrapper for the pin-payments (pin.net.au) API"
|
16
|
-
s.email = "dnitza@gmail.com"
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["Daniel Nitsikopoulos".freeze]
|
14
|
+
s.date = "2018-06-15"
|
15
|
+
s.description = "A Ruby gem wrapper for the pin-payments (pin.net.au) API".freeze
|
16
|
+
s.email = "dnitza@gmail.com".freeze
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE.txt",
|
19
19
|
"README.md"
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.files = [
|
22
22
|
".document",
|
23
23
|
".travis.yml",
|
24
|
+
"CHANGELOG.md",
|
24
25
|
"Gemfile",
|
25
26
|
"Gemfile.lock",
|
26
27
|
"Guardfile",
|
@@ -38,9 +39,12 @@ Gem::Specification.new do |s|
|
|
38
39
|
"lib/pin_up/client.rb",
|
39
40
|
"lib/pin_up/customer.rb",
|
40
41
|
"lib/pin_up/pin_errors.rb",
|
42
|
+
"lib/pin_up/plan.rb",
|
41
43
|
"lib/pin_up/recipient.rb",
|
42
44
|
"lib/pin_up/refund.rb",
|
45
|
+
"lib/pin_up/subscription.rb",
|
43
46
|
"lib/pin_up/transfer.rb",
|
47
|
+
"lib/pin_up/webhook_endpoints.rb",
|
44
48
|
"pin_up.gemspec",
|
45
49
|
"spec/balance_spec.rb",
|
46
50
|
"spec/bank_accounts_spec.rb",
|
@@ -50,53 +54,53 @@ Gem::Specification.new do |s|
|
|
50
54
|
"spec/client_spec.rb",
|
51
55
|
"spec/customers_spec.rb",
|
52
56
|
"spec/errors_spec.rb",
|
57
|
+
"spec/plan_spec.rb",
|
53
58
|
"spec/recipients_spec.rb",
|
54
59
|
"spec/refund_spec.rb",
|
55
60
|
"spec/spec_helper.rb",
|
56
|
-
"spec/
|
61
|
+
"spec/subscription_spec.rb",
|
62
|
+
"spec/transfers_spec.rb",
|
63
|
+
"spec/webhook_endpoints_spec.rb"
|
57
64
|
]
|
58
|
-
s.homepage = "http://github.com/dNitza/pin_up"
|
59
|
-
s.licenses = ["MIT"]
|
60
|
-
s.rubygems_version = "2.
|
61
|
-
s.summary = "A Ruby gem wrapper for the pin-payments API"
|
65
|
+
s.homepage = "http://github.com/dNitza/pin_up".freeze
|
66
|
+
s.licenses = ["MIT".freeze]
|
67
|
+
s.rubygems_version = "2.7.3".freeze
|
68
|
+
s.summary = "A Ruby gem wrapper for the pin-payments API".freeze
|
62
69
|
|
63
70
|
if s.respond_to? :specification_version then
|
64
71
|
s.specification_version = 4
|
65
72
|
|
66
73
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
67
|
-
s.add_runtime_dependency(%q<httparty
|
68
|
-
s.add_development_dependency(%q<
|
69
|
-
s.add_development_dependency(%q<
|
70
|
-
s.add_development_dependency(%q<
|
71
|
-
s.add_development_dependency(%q<
|
72
|
-
s.add_development_dependency(%q<
|
73
|
-
s.add_development_dependency(%q<
|
74
|
-
s.add_development_dependency(%q<
|
75
|
-
s.add_development_dependency(%q<guard
|
76
|
-
s.add_development_dependency(%q<terminal-notifier-guard>, ["~> 1.5.3"])
|
74
|
+
s.add_runtime_dependency(%q<httparty>.freeze, [">= 0.11.0"])
|
75
|
+
s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
76
|
+
s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
|
77
|
+
s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.3.9"])
|
78
|
+
s.add_development_dependency(%q<simplecov>.freeze, ["~> 0.7.1"])
|
79
|
+
s.add_development_dependency(%q<webmock>.freeze, [">= 0"])
|
80
|
+
s.add_development_dependency(%q<vcr>.freeze, [">= 0"])
|
81
|
+
s.add_development_dependency(%q<guard-rspec>.freeze, [">= 0"])
|
82
|
+
s.add_development_dependency(%q<terminal-notifier-guard>.freeze, ["~> 1.5.3"])
|
77
83
|
else
|
78
|
-
s.add_dependency(%q<httparty
|
79
|
-
s.add_dependency(%q<
|
80
|
-
s.add_dependency(%q<
|
81
|
-
s.add_dependency(%q<
|
82
|
-
s.add_dependency(%q<
|
83
|
-
s.add_dependency(%q<
|
84
|
-
s.add_dependency(%q<
|
85
|
-
s.add_dependency(%q<
|
86
|
-
s.add_dependency(%q<guard
|
87
|
-
s.add_dependency(%q<terminal-notifier-guard>, ["~> 1.5.3"])
|
84
|
+
s.add_dependency(%q<httparty>.freeze, [">= 0.11.0"])
|
85
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
86
|
+
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
87
|
+
s.add_dependency(%q<jeweler>.freeze, ["~> 2.3.9"])
|
88
|
+
s.add_dependency(%q<simplecov>.freeze, ["~> 0.7.1"])
|
89
|
+
s.add_dependency(%q<webmock>.freeze, [">= 0"])
|
90
|
+
s.add_dependency(%q<vcr>.freeze, [">= 0"])
|
91
|
+
s.add_dependency(%q<guard-rspec>.freeze, [">= 0"])
|
92
|
+
s.add_dependency(%q<terminal-notifier-guard>.freeze, ["~> 1.5.3"])
|
88
93
|
end
|
89
94
|
else
|
90
|
-
s.add_dependency(%q<httparty
|
91
|
-
s.add_dependency(%q<
|
92
|
-
s.add_dependency(%q<
|
93
|
-
s.add_dependency(%q<
|
94
|
-
s.add_dependency(%q<
|
95
|
-
s.add_dependency(%q<
|
96
|
-
s.add_dependency(%q<
|
97
|
-
s.add_dependency(%q<
|
98
|
-
s.add_dependency(%q<guard
|
99
|
-
s.add_dependency(%q<terminal-notifier-guard>, ["~> 1.5.3"])
|
95
|
+
s.add_dependency(%q<httparty>.freeze, [">= 0.11.0"])
|
96
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
97
|
+
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
98
|
+
s.add_dependency(%q<jeweler>.freeze, ["~> 2.3.9"])
|
99
|
+
s.add_dependency(%q<simplecov>.freeze, ["~> 0.7.1"])
|
100
|
+
s.add_dependency(%q<webmock>.freeze, [">= 0"])
|
101
|
+
s.add_dependency(%q<vcr>.freeze, [">= 0"])
|
102
|
+
s.add_dependency(%q<guard-rspec>.freeze, [">= 0"])
|
103
|
+
s.add_dependency(%q<terminal-notifier-guard>.freeze, ["~> 1.5.3"])
|
100
104
|
end
|
101
105
|
end
|
102
106
|
|
data/spec/cards_spec.rb
CHANGED
@@ -1,12 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe 'Card', :vcr, class: Pin::Card do
|
4
|
+
let(:card_1) {
|
5
|
+
{ number: '5520000000000000',
|
6
|
+
expiry_month: '12',
|
7
|
+
expiry_year: '2025',
|
8
|
+
cvc: '123',
|
9
|
+
name: 'Roland Robot',
|
10
|
+
address_line1: '123 Fake Street',
|
11
|
+
address_city: 'Melbourne',
|
12
|
+
address_postcode: '1234',
|
13
|
+
address_state: 'Vic',
|
14
|
+
address_country: 'Australia' }
|
15
|
+
}
|
16
|
+
|
4
17
|
before(:each) do
|
5
18
|
Pin::Base.new(ENV['PIN_SECRET'], :test)
|
6
19
|
end
|
7
20
|
|
8
21
|
it 'should create a card and respond with the card detail from pin' do
|
9
|
-
|
10
|
-
expect(Pin::Card.create(options)['token']).to match(/^[a-z]{4}[_]/)
|
22
|
+
expect(Pin::Card.create(card_1)['token']).to match(/^[a-z]{4}[_]/)
|
11
23
|
end
|
12
24
|
end
|
data/spec/charges_spec.rb
CHANGED
@@ -1,8 +1,58 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Charge', :vcr, class: Pin::Charges do
|
4
|
+
let(:card_1) {
|
5
|
+
{ number: '5520000000000000',
|
6
|
+
expiry_month: '12',
|
7
|
+
expiry_year: '2025',
|
8
|
+
cvc: '123',
|
9
|
+
name: 'Roland Robot',
|
10
|
+
address_line1: '123 Fake Street',
|
11
|
+
address_city: 'Melbourne',
|
12
|
+
address_postcode: '1234',
|
13
|
+
address_state: 'Vic',
|
14
|
+
address_country: 'Australia' }
|
15
|
+
}
|
16
|
+
|
17
|
+
let(:customer_token) {
|
18
|
+
Pin::Customer.create('email@example.com', card_1)['token']
|
19
|
+
}
|
20
|
+
|
21
|
+
let(:charge) {
|
22
|
+
Pin::Charges.create(email: 'email@example.com',
|
23
|
+
description: 'Charge description',
|
24
|
+
amount: '500',
|
25
|
+
currency: 'AUD',
|
26
|
+
number: '5520000000000000',
|
27
|
+
ip_address: '203.192.1.172',
|
28
|
+
customer_token: customer_token)
|
29
|
+
}
|
30
|
+
|
31
|
+
let(:charge_hash) {
|
32
|
+
{ email: 'email@example.com',
|
33
|
+
description: 'A new charge from testing Pin gem',
|
34
|
+
amount: '400',
|
35
|
+
currency: 'AUD',
|
36
|
+
ip_address: '127.0.0.1',
|
37
|
+
customer_token: customer_token }
|
38
|
+
}
|
39
|
+
|
40
|
+
let(:charge_capture_false) {
|
41
|
+
{ email: 'email@example.com',
|
42
|
+
description: 'A new captured charge from testing Pin gem',
|
43
|
+
amount: '400',
|
44
|
+
currency: 'AUD',
|
45
|
+
ip_address: '127.0.0.1',
|
46
|
+
customer_token: customer_token,
|
47
|
+
capture: false }
|
48
|
+
}
|
49
|
+
|
4
50
|
before(:each) do
|
5
51
|
Pin::Base.new(ENV['PIN_SECRET'], :test)
|
52
|
+
# Create a customer
|
53
|
+
customer_token
|
54
|
+
# Create a charge
|
55
|
+
charge
|
6
56
|
end
|
7
57
|
|
8
58
|
it 'should list charges in Pin' do
|
@@ -14,17 +64,15 @@ describe 'Charge', :vcr, class: Pin::Charges do
|
|
14
64
|
end
|
15
65
|
|
16
66
|
it 'should create a charge given details' do
|
17
|
-
|
18
|
-
options = { email: 'email@example.com', description: 'A new charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', customer_token: customer['token'] }
|
19
|
-
expect(Pin::Charges.create(options)['success']).to eq true
|
67
|
+
expect(Pin::Charges.create(charge_hash)['success']).to eq true
|
20
68
|
end
|
21
69
|
|
22
70
|
it 'should show a charge given a token' do
|
23
|
-
expect(Pin::Charges.find('
|
71
|
+
expect(Pin::Charges.find(charge['token'])['token']).to match(/^[a-z]{2}[_]/)
|
24
72
|
end
|
25
73
|
|
26
74
|
it 'should show a charge given a search term' do
|
27
|
-
expect(Pin::Charges.search(query: '
|
75
|
+
expect(Pin::Charges.search(query: 'Charge Desc', end_date: 'Aug 31, 2025')).to_not eq []
|
28
76
|
end
|
29
77
|
|
30
78
|
it 'should return pagination if "pagination" is true' do
|
@@ -36,23 +84,19 @@ describe 'Charge', :vcr, class: Pin::Charges do
|
|
36
84
|
end
|
37
85
|
|
38
86
|
it 'should return pagination for search if "pagination" is true' do
|
39
|
-
expect(Pin::Charges.search(3, true, query: '
|
87
|
+
expect(Pin::Charges.search(3, true, query: 'Charge Desc', end_date: 'Aug 31, 2025')[:pagination]['current']).to eq 3
|
40
88
|
end
|
41
89
|
|
42
90
|
it 'should list charges for search on a page given a page' do
|
43
|
-
expect(Pin::Charges.search(1, query: '
|
91
|
+
expect(Pin::Charges.search(1, query: 'Charge Desc', end_date: 'Aug 31, 2025')).to_not eq []
|
44
92
|
end
|
45
93
|
|
46
94
|
it 'should create a pre-auth (capture a charge)' do
|
47
|
-
|
48
|
-
options = { email: 'email@example.com', description: 'A new captured charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', customer_token: customer['token'], capture: false }
|
49
|
-
expect(Pin::Charges.create(options)['captured']).to eq false
|
95
|
+
expect(Pin::Charges.create(charge_capture_false)['captured']).to eq false
|
50
96
|
end
|
51
97
|
|
52
98
|
it 'should capture a charge' do
|
53
|
-
|
54
|
-
options = { email: 'email@example.com', description: 'A new captured charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', customer_token: customer['token'], capture: false }
|
55
|
-
token = Pin::Charges.create(options)['token']
|
99
|
+
token = Pin::Charges.create(charge_capture_false)['token']
|
56
100
|
expect(Pin::Charges.capture(token)['success']).to eq true
|
57
101
|
end
|
58
102
|
end
|