pin-payments 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTVmN2FlMGRkMWU5ODkwMjRhMWI1MTllY2RhOThlMDIxYmQ3YzI5Ng==
5
+ data.tar.gz: !binary |-
6
+ Yzc5MjJmMmM5OGYzODczYzYxM2Q1OTVlMTdlNWJhZmM0OWU4MmJkNw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YjgyNWQzODJiZDJhMDM2MGM2M2I3OTMyOTBmOTU1ZDI2MzIwM2VhOTIzYTgz
10
+ YTI3MTFiNmIzMDUzN2U0OWIyYTIyMGUxZjRmYzc0MDBjMTBkNDkxYjM2NWJi
11
+ OTNlNTMyYjMzY2MwMDA1MWYxYjFhYmRjNTMxMjRkMzdjNDE4YmY=
12
+ data.tar.gz: !binary |-
13
+ MDY2ZmRiMmY4ODU1ZGY2MjcxMjY3ODI3YTg2NDA3ZmFhNmFlZjhlNjEwZTBj
14
+ NzczNWU4NGVlOThiNDM3ODhjM2MxNGE4NmQyNGFkMTc3MzYwNmIyODhmYTNh
15
+ Y2M0MmYzOGU4YzM3NmQzOGFmMzgxZDlhOWNiMmUwOTBiZWU3Njc=
data/lib/base.rb ADDED
@@ -0,0 +1,26 @@
1
+ module Pin
2
+ class Base
3
+ include HTTParty
4
+ base_uri "https://test-api.pin.net.au/1"
5
+
6
+ def self.setup!(key, mode = :live)
7
+ @@auth = {username: key, password: ''}
8
+ uri = if mode == :test
9
+ "https://test-api.pin.net.au/1"
10
+ elsif mode == :live
11
+ "https://api.pin.net.au/1"
12
+ else
13
+ raise "Incorrect API mode! Must be :live or :test (leave blank for :live)."
14
+ end
15
+ base_uri uri
16
+ end
17
+
18
+ protected
19
+ def self.authenticated_post(url, body)
20
+ post(url, body: body, basic_auth: @@auth)
21
+ end
22
+ def self.authenticated_get(url, query = {})
23
+ get(url, query: query, basic_auth: @@auth)
24
+ end
25
+ end
26
+ end
data/lib/card.rb ADDED
@@ -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
+ new(response.parsed_response['response'])
28
+ else
29
+ # handle the error
30
+ false
31
+ end
32
+ end
33
+ end
34
+ end
data/lib/charge.rb ADDED
@@ -0,0 +1,18 @@
1
+ module Pin
2
+ class Charge < Base
3
+ attr_accessor :email, :description, :amount, :currency, :ip_address
4
+
5
+ # options should be a hash with the following params
6
+ # email, description, amount, currency, ip_address are mandatory
7
+ # identifier must be a hash, can take the forms
8
+ # {card: <Pin::Card>}
9
+ # {card_token: String<"...">}
10
+ # {customer_token: String<"...">}
11
+ # {customer: <Pin::Customer>}
12
+ # eg. {email: 'alex@payaus.com', description: '1 month of PayAus', amount: 19900, currency: 'AUD', ip_address: '203.192.1.172', customer_token: 'asdf'}
13
+ def self.create(options = {})
14
+ options[:customer_token] = options.delete(:customer).token if options[:customer].present?
15
+ authenticated_post '/charges', options
16
+ end
17
+ end
18
+ end
data/lib/customer.rb ADDED
@@ -0,0 +1,44 @@
1
+ module Pin
2
+ class Customer < Base
3
+ attr_accessor :email, :created_at, :token, :card
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)
11
+ end
12
+ end
13
+ end
14
+
15
+ # email should be a string
16
+ # card_or_token can be a Pin::Card object
17
+ # or a card_token (as a string)
18
+ def self.create(email, card_or_token)
19
+ body = if card_or_token.respond_to?(:to_hash) # card
20
+ {card: card_or_token.to_hash}
21
+ else # token
22
+ {card_token: card_or_token}
23
+ end.merge(email: email)
24
+
25
+ authenticated_post '/customers', body
26
+ end
27
+
28
+ def self.all # TODO: pagination
29
+ response = authenticated_get '/customers'
30
+ customers = []
31
+ if response.code == 200
32
+ response.parsed_response['response'].each do |customer|
33
+ customers << new(customer)
34
+ end
35
+ end
36
+ customers
37
+ end
38
+
39
+ def self.find(token)
40
+ response = authenticated_get "/customers/#{token}"
41
+ new(response.parsed_response['response'])
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,6 @@
1
+ require 'httparty'
2
+
3
+ require 'base'
4
+ require 'card'
5
+ require 'charge'
6
+ require 'customer'
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pin-payments
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Ghiculescu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
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
+ description: A wrapper for the Pin Payments (https://pin.net.au/) API
42
+ email: alexghiculescu@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/base.rb
48
+ - lib/card.rb
49
+ - lib/charge.rb
50
+ - lib/customer.rb
51
+ - lib/pin-payments.rb
52
+ homepage: https://github.com/ghiculescu/pin-payments
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.0.3
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Pin Payments API wrapper
76
+ test_files: []
77
+ has_rdoc: