white_payments 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ gem 'httparty'
5
+
6
+ group :test do
7
+ gem 'minitest'
8
+ gem 'turn'
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ white (1.0.0)
5
+ httparty (~> 0.13)
6
+ json (~> 1.8.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ansi (1.4.3)
12
+ httparty (0.13.1)
13
+ json (~> 1.8)
14
+ multi_xml (>= 0.5.2)
15
+ json (1.8.1)
16
+ minitest (4.7.5)
17
+ multi_xml (0.5.5)
18
+ rake (10.3.2)
19
+ turn (0.9.7)
20
+ ansi
21
+ minitest (~> 4)
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ httparty
28
+ minitest
29
+ rake
30
+ turn
31
+ white!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 WhitePayments
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task :default => [:test]
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.pattern = './spec/**/*_spec.rb'
8
+ end
data/lib/white.rb ADDED
@@ -0,0 +1,56 @@
1
+ require "httparty"
2
+ require "white/charge"
3
+ require "white/errors/white_error"
4
+ require "white/errors/authentication_error"
5
+ require "white/errors/card_error"
6
+ require "white/errors/invalid_request_error"
7
+
8
+ module White
9
+
10
+ include HTTParty
11
+
12
+ @api_base = 'https://api.whitepayments.com'
13
+
14
+ def self.api_url(url='')
15
+ @api_base + url
16
+ end
17
+
18
+ def self.handle_response(response)
19
+ body = JSON.parse(response.body);
20
+ if(response.code == 400 and body['error']['type'] == 'card_error')
21
+ raise White::CardError.new(body['error']['message'], body['error']['code'], 400)
22
+ end
23
+ if(response.code == 422)
24
+ raise White::InvalidRequestError.new(body['error']['message'], 422)
25
+ end
26
+
27
+ if(response.code == 401)
28
+ raise White::AuthenticationError.new(body['error']['message'], 422)
29
+ end
30
+
31
+ if(response.code >= 500 && response.code < 600)
32
+ raise White::WhiteError.new(body['error']['message'], response.code)
33
+ end
34
+
35
+ body
36
+ end
37
+
38
+ def self.post(url, body={})
39
+ options = {basic_auth: {username: api_key, password: ''}}
40
+ options.merge!({body: body})
41
+ response = HTTParty.post(url, options)
42
+ self.handle_response(response)
43
+
44
+ end
45
+
46
+ def self.get(url, query={})
47
+ options = {basic_auth: {username: api_key, password: ''}}
48
+ options.merge!({query: query})
49
+ response = HTTParty.get(url, options)
50
+ JSON.parse(response.body);
51
+ end
52
+
53
+ class << self
54
+ attr_accessor :api_key
55
+ end
56
+ end
@@ -0,0 +1,12 @@
1
+ module White
2
+ class Charge
3
+
4
+ def self.create(params={})
5
+ White.post(White.api_url('/v1/charges'), params)
6
+ end
7
+
8
+ def self.all
9
+ White.get(White.api_url('/v1/charges'))
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module White
2
+ class AuthenticationError < WhiteError
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ module White
2
+ class CardError < WhiteError
3
+
4
+ attr_reader :code
5
+
6
+ def initialize(message, code, http_status=nil)
7
+ super(message, http_status)
8
+ @code = code
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module White
2
+ class InvalidRequestError < WhiteError
3
+ end
4
+ end
@@ -0,0 +1,16 @@
1
+ module White
2
+ class WhiteError < StandardError
3
+ attr_reader :message
4
+ attr_reader :http_status
5
+
6
+ def initialize(message=nil, http_status=nil)
7
+ @message = message
8
+ @http_status = http_status
9
+ end
10
+
11
+ def to_s
12
+ status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
13
+ "#{status_string}#{@message}"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module White
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,28 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe White::Charge do
4
+
5
+ it "must create a new charge" do
6
+ White.api_key = "sk_test_1234567890abcdefghijklmnopq"
7
+
8
+ response = White::Charge.create(
9
+ :amount => 400,
10
+ :currency => "usd",
11
+ :card => {
12
+ :number => "4242424242424242",
13
+ :exp_month => 11,
14
+ :exp_year => 2014,
15
+ :cvv => 123
16
+ },
17
+ :description => "Charge for test@example.com"
18
+ )
19
+
20
+ response['is_captured'].must_equal true
21
+ end
22
+
23
+ it "must list created charges" do
24
+ response = White::Charge.all()
25
+ response.wont_be_empty
26
+ end
27
+
28
+ end
@@ -0,0 +1,151 @@
1
+ require_relative '../../../spec_helper'
2
+
3
+ describe White::CardError do
4
+
5
+ it "must be thown with card_declined" do
6
+ White.api_key = "sk_test_1234567890abcdefghijklmnopq"
7
+
8
+ begin
9
+ response = White::Charge.create(
10
+ :amount => 400,
11
+ :currency => "usd",
12
+ :card => {
13
+ :number => "4000000000000002",
14
+ :exp_month => 11,
15
+ :exp_year => 2014,
16
+ :cvv => 123
17
+ },
18
+ :description => "Charge for test@example.com"
19
+ )
20
+ rescue White::CardError => e
21
+ e.code.must_equal 'card_declined'
22
+ e.http_status.must_equal 400
23
+ end
24
+ end
25
+
26
+ it "must be thown with invalid_cvc" do
27
+ White.api_key = "sk_test_1234567890abcdefghijklmnopq"
28
+
29
+ begin
30
+ response = White::Charge.create(
31
+ :amount => 400,
32
+ :currency => "usd",
33
+ :card => {
34
+ :number => "4000000000000127",
35
+ :exp_month => 11,
36
+ :exp_year => 2014,
37
+ :cvv => 123
38
+ },
39
+ :description => "Charge for test@example.com"
40
+ )
41
+ rescue White::CardError => e
42
+ e.code.must_equal 'invalid_cvc'
43
+ e.http_status.must_equal 400
44
+ end
45
+ end
46
+
47
+ it "must be thown with expired_card" do
48
+ White.api_key = "sk_test_1234567890abcdefghijklmnopq"
49
+
50
+ begin
51
+ response = White::Charge.create(
52
+ :amount => 400,
53
+ :currency => "usd",
54
+ :card => {
55
+ :number => "4000000000000069",
56
+ :exp_month => 11,
57
+ :exp_year => 2014,
58
+ :cvv => 123
59
+ },
60
+ :description => "Charge for test@example.com"
61
+ )
62
+ rescue White::CardError => e
63
+ e.code.must_equal 'expired_card'
64
+ e.http_status.must_equal 400
65
+ end
66
+ end
67
+
68
+ it "must be thown with processing_error" do
69
+ White.api_key = "sk_test_1234567890abcdefghijklmnopq"
70
+
71
+ begin
72
+ response = White::Charge.create(
73
+ :amount => 400,
74
+ :currency => "usd",
75
+ :card => {
76
+ :number => "4000000000000119",
77
+ :exp_month => 11,
78
+ :exp_year => 2014,
79
+ :cvv => 123
80
+ },
81
+ :description => "Charge for test@example.com"
82
+ )
83
+ rescue White::CardError => e
84
+ e.code.must_equal 'processing_error'
85
+ e.http_status.must_equal 400
86
+ end
87
+ end
88
+
89
+ it "must be thown with invalid_number" do
90
+ White.api_key = "sk_test_1234567890abcdefghijklmnopq"
91
+
92
+ begin
93
+ response = White::Charge.create(
94
+ :amount => 400,
95
+ :currency => "usd",
96
+ :card => {
97
+ :number => "1234123412341234",
98
+ :exp_month => 11,
99
+ :exp_year => 2014,
100
+ :cvv => 123
101
+ },
102
+ :description => "Charge for test@example.com"
103
+ )
104
+ rescue White::CardError => e
105
+ e.code.must_equal 'invalid_number'
106
+ e.http_status.must_equal 400
107
+ end
108
+ end
109
+
110
+ it "must be thown with invalid_expiry_month" do
111
+ White.api_key = "sk_test_1234567890abcdefghijklmnopq"
112
+
113
+ begin
114
+ response = White::Charge.create(
115
+ :amount => 400,
116
+ :currency => "usd",
117
+ :card => {
118
+ :number => "4242424242424242",
119
+ :exp_month => 15,
120
+ :exp_year => 2014,
121
+ :cvv => 123
122
+ },
123
+ :description => "Charge for test@example.com"
124
+ )
125
+ rescue White::CardError => e
126
+ e.code.must_equal 'invalid_expiry_month'
127
+ e.http_status.must_equal 400
128
+ end
129
+ end
130
+
131
+ it "must be thown with invalid_expiry_year" do
132
+ White.api_key = "sk_test_1234567890abcdefghijklmnopq"
133
+
134
+ begin
135
+ response = White::Charge.create(
136
+ :amount => 400,
137
+ :currency => "usd",
138
+ :card => {
139
+ :number => "4242424242424242",
140
+ :exp_month => 12,
141
+ :exp_year => 2100,
142
+ :cvv => 123
143
+ },
144
+ :description => "Charge for test@example.com"
145
+ )
146
+ rescue White::CardError => e
147
+ e.code.must_equal 'invalid_expiry_year'
148
+ e.http_status.must_equal 400
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../../../spec_helper'
2
+
3
+ describe White::InvalidRequestError do
4
+
5
+ it "must be thown with invalid_request_error" do
6
+ White.api_key = "sk_test_1234567890abcdefghijklmnopq"
7
+
8
+ lambda {
9
+ response = White::Charge.create(
10
+ :amount => -1,
11
+ :currency => "usd",
12
+ :card => {
13
+ :number => "4242424242424242",
14
+ :exp_month => 11,
15
+ :exp_year => 2014,
16
+ :cvv => 123
17
+ },
18
+ :description => "Charge for test@example.com"
19
+ )
20
+ }.must_raise White::InvalidRequestError
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../../../spec_helper'
2
+
3
+ describe White::AuthenticationError do
4
+
5
+ it "must be thown with an invalid key" do
6
+ White.api_key = "invalid"
7
+
8
+ lambda {
9
+ response = White::Charge.create(
10
+ :amount => 400,
11
+ :currency => "usd",
12
+ :card => {
13
+ :number => "3566002020360505",
14
+ :exp_month => 11,
15
+ :exp_year => 2014,
16
+ :cvv => 123
17
+ },
18
+ :description => "Charge for test@example.com"
19
+ )
20
+ }.must_raise White::AuthenticationError
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../../../spec_helper'
2
+
3
+ describe White::WhiteError do
4
+
5
+ it "must be thown" do
6
+ White.api_key = "sk_test_1234567890abcdefghijklmnopq"
7
+
8
+ lambda {
9
+ response = White::Charge.create(
10
+ :amount => 400,
11
+ :currency => "usd",
12
+ :card => {
13
+ :number => "3566002020360505",
14
+ :exp_month => 11,
15
+ :exp_year => 2014,
16
+ :cvv => 123
17
+ },
18
+ :description => "Charge for test@example.com"
19
+ )
20
+ }.must_raise White::WhiteError
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ #we need the actual library file
2
+ require_relative '../lib/white'
3
+ # For Ruby < 1.9.3, use this instead of require_relative
4
+ # require(File.expand_path('../../lib/dish', __FILE__))
5
+
6
+ #dependencies
7
+ gem 'minitest'
8
+ require 'minitest/autorun'
data/white.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+
3
+ require 'white/version'
4
+
5
+ spec = Gem::Specification.new do |s|
6
+ s.name = 'white_payments'
7
+ s.version = White::VERSION
8
+ s.summary = 'Ruby bindings for the White API'
9
+ s.description = 'White is the easiest way to accept payments online in the middle east. See https://whitepayments.com for details.'
10
+ s.authors = ['Yazin Alirhayim','Sebastian Choren']
11
+ s.email = ['yazin@whitepayments.com']
12
+ s.homepage = 'https://whitepayments.com/docs/'
13
+ s.license = 'MIT'
14
+
15
+ s.add_dependency('httparty', '~> 0.13')
16
+ s.add_dependency('json', '~> 1.8.1')
17
+
18
+ s.add_development_dependency('minitest', '~> 4.7.5')
19
+ s.add_development_dependency('turn', '~> 0.9.7')
20
+ s.add_development_dependency('rake')
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- spec/*`.split("\n")
24
+ s.require_paths = ['lib']
25
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: white_payments
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yazin Alirhayim
9
+ - Sebastian Choren
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-10-20 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '0.13'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '0.13'
31
+ - !ruby/object:Gem::Dependency
32
+ name: json
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 1.8.1
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.8.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 4.7.5
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 4.7.5
63
+ - !ruby/object:Gem::Dependency
64
+ name: turn
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: 0.9.7
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 0.9.7
79
+ - !ruby/object:Gem::Dependency
80
+ name: rake
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ description: White is the easiest way to accept payments online in the middle east.
96
+ See https://whitepayments.com for details.
97
+ email:
98
+ - yazin@whitepayments.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .gitignore
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - LICENSE
107
+ - Rakefile
108
+ - lib/white.rb
109
+ - lib/white/charge.rb
110
+ - lib/white/errors/authentication_error.rb
111
+ - lib/white/errors/card_error.rb
112
+ - lib/white/errors/invalid_request_error.rb
113
+ - lib/white/errors/white_error.rb
114
+ - lib/white/version.rb
115
+ - spec/lib/white/charge_spec.rb
116
+ - spec/lib/white/error/card_error_spec.rb
117
+ - spec/lib/white/error/invalid_request_error_spec.rb
118
+ - spec/lib/white/error/white_authentication_error.rb
119
+ - spec/lib/white/error/white_error_spec.rb
120
+ - spec/spec_helper.rb
121
+ - white.gemspec
122
+ homepage: https://whitepayments.com/docs/
123
+ licenses:
124
+ - MIT
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 1.8.23
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: Ruby bindings for the White API
147
+ test_files:
148
+ - spec/lib/white/charge_spec.rb
149
+ - spec/lib/white/error/card_error_spec.rb
150
+ - spec/lib/white/error/invalid_request_error_spec.rb
151
+ - spec/lib/white/error/white_authentication_error.rb
152
+ - spec/lib/white/error/white_error_spec.rb
153
+ - spec/spec_helper.rb