simple_pin 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/simple_pin.rb +75 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b9a7656a216323fc7a20c30e3b577c2a2a37c145
|
4
|
+
data.tar.gz: 3c115ffb44047595eade9171b701bf2ddc1ce2b8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 156f6f4e9e66e6661dce2ba89acf9c853e15397e7841b4a43e9e6cc10949d2a1717a318202facf363eb47786d7a1ecbf1720eacdd199d1151a7d416eef159424
|
7
|
+
data.tar.gz: a755159b33a326da303fbe1d3d2d76c6d7c2de7b6f0530fb9277bc2144d931129bef7619a7fd63bb3b714e793a559df7dce23fd4f101b960e85b0e7c9ab0cb6f
|
data/lib/simple_pin.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module SimplePin
|
4
|
+
class Pin
|
5
|
+
include HTTParty
|
6
|
+
attr_accessor :auth, :base_url
|
7
|
+
|
8
|
+
##
|
9
|
+
# Create a new Pin instance
|
10
|
+
# key: Your Pin secret key
|
11
|
+
# env: The environment you want to use.
|
12
|
+
def initialize(key = '', env = :test)
|
13
|
+
@key = key
|
14
|
+
env = env.to_sym
|
15
|
+
@auth = { username: @key, password: '' }
|
16
|
+
@base_url = if env == :live
|
17
|
+
'https://api.pin.net.au/1/'
|
18
|
+
else
|
19
|
+
'https://test-api.pin.net.au/1/'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Pin error response
|
25
|
+
##
|
26
|
+
class PinError < StandardError
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Create a charge given charge details and a card,
|
31
|
+
# https://pin.net.au/docs/api/charges
|
32
|
+
# returns: a charge object
|
33
|
+
##
|
34
|
+
def create_charge(options = {})
|
35
|
+
build_response(make_request(:post, url: 'charges', options: options))
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Creates a card given a hash of options
|
40
|
+
# https://pin.net.au/docs/api/cards
|
41
|
+
# returns: a card object
|
42
|
+
##
|
43
|
+
def create_card(options = {})
|
44
|
+
build_response(make_request(:post, url: 'cards', options: options))
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Create a customer given customer details and a card_token
|
49
|
+
# https://pin.net.au/docs/api/customers
|
50
|
+
# returns: a customer object
|
51
|
+
##
|
52
|
+
def create_customer(options = {})
|
53
|
+
build_response(make_request(:post, url: 'customers', options: options))
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def build_response(response)
|
59
|
+
fail PinError, error_message(response) unless response.code == 201
|
60
|
+
response['response']
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# Sends an authenticated request to pin's server
|
65
|
+
##
|
66
|
+
def make_request(method, args)
|
67
|
+
@args = args
|
68
|
+
HTTParty.send(method, "#{@base_url}#{args[:url]}", body: @args[:options], basic_auth: @auth)
|
69
|
+
end
|
70
|
+
|
71
|
+
def error_message(response)
|
72
|
+
%(Pin API returned code #{response.code} for #{@base_url}, with error: '#{response.body}')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_pin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- StevenIseki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple gem for creating customers and charges using pin-payments (pin.net.au)
|
14
|
+
API
|
15
|
+
email: stevenisekimartin@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/simple_pin.rb
|
21
|
+
homepage: http://rubygems.org/gems/simple_pin
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.5.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: simple_pin gem for pin-payment
|
45
|
+
test_files: []
|