white_payments 1.0.0 → 2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 712bd37dfaeb37f7d4cbd0af582569b36c70bd7c
4
+ data.tar.gz: 5709c6921d290afa57be539ba845f87906951a56
5
+ SHA512:
6
+ metadata.gz: a0a377508b41862e144a2b45d5c7f7123fbf75b6dcdc35e9b2a15464b7a92832fe291eae11aab4de175910baef9a1bcaaacd19fdcd9e0ef5ff850671989e1948
7
+ data.tar.gz: b8aee9d2fadff3cbb609f933afb722ecbb9c715b7fefb0dc1bfaf76bbe90d28a30d3e82ba11745f9442d6b51470f91de5850e0ede78801c31a9d83f97103e061
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # White Ruby
2
+
3
+ White makes accepting payments in the Middle East ridiculously easy. Sign up for an account at [whitepayments.com](http://whitepayments.com).
4
+
5
+ ## Getting Started
6
+
7
+ Using White with your Ruby project is simple. If you're using [bundler](http://bundler.io) (and really, who isn't these days amirite?), you just need to add one line to your `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'white_payments'
11
+ ```
12
+
13
+ Now, running `bundle install` will pull the library directly to your local project.
14
+
15
+ ## Using White
16
+
17
+ You'll need an account with White if you don't already have one (grab one real quick at [whitepayments.com](http://whitepayments.com) and come back .. we'll wait).
18
+
19
+ Got an account? Great .. let's get busy.
20
+
21
+ ### 1. Initializing White
22
+
23
+ To get started, you'll need to initialize White with your secret API key. Here's how that looks (we're using a test key, so no real money will be exchanging hands):
24
+
25
+ ```ruby
26
+ require 'white'
27
+
28
+ White.api_key = "test_sec_k_25dd497d7e657bb761ad6"
29
+ ```
30
+
31
+ That's it! You probably want to do something with the White object though -- it gets really bored when it doesn't have anything to do.
32
+
33
+ Let's run a transaction, shall we.
34
+
35
+ ### 2. Processing a transaction through White
36
+
37
+ Now, for the fun part. Here's all the code you need to process a transaction with White:
38
+
39
+ ```ruby
40
+ White::Charge.create(
41
+ :amount => 5,
42
+ :currency => "aed",
43
+ :card => {
44
+ :number => "4242424242424242",
45
+ :exp_month => 11,
46
+ :exp_year => 2016,
47
+ :cvv => 123
48
+ },
49
+ :description => "Charge for test@example.com"
50
+ )
51
+ ```
52
+
53
+ This transaction should be successful since we used the `4242 4242 4242 4242` test credit card. For a complete list of test cards, and their expected output you can check out this link [here](https://whitepayments.com/docs/testing/).
54
+
55
+ How can you tell that it was successful? Well, if no exception is raised then you're in the clear.
56
+
57
+ ### 3. Handling Errors
58
+
59
+ Any errors that may occur during a transaction is raised as an Exception. Here's an example of how you can handle errors with White:
60
+
61
+ ```ruby
62
+ begin
63
+ # Use White's bindings...
64
+
65
+ rescue White::BankingError => e
66
+ # Since it's a decline, White::BankingError will be caught
67
+ puts "Status is: #{e.http_status}"
68
+ puts "Code is: #{e.code}"
69
+ puts "Message is: #{e.message}"
70
+
71
+ rescue White::RequestError => e
72
+ # Invalid parameters were supplied to White's API
73
+
74
+ rescue White::AuthenticationError => e
75
+ # There's something wrong with that API key you passed
76
+
77
+ rescue White::ProcessingError => e
78
+ # There's something wrong on White's end
79
+
80
+ rescue White::WhiteError => e
81
+ # Display a very generic error to the user, and maybe send
82
+ # yourself an email
83
+
84
+ rescue => e
85
+ # Something else happened, completely unrelated to White
86
+ end
87
+ ```
88
+
89
+ ## Testing White
90
+ If you're looking to contribute to White, then grab this repo and run `rake` on your local machine to run the unit tests.
91
+
92
+ ## Contributing
93
+
94
+ Read our [Contributing Guidelines](CONTRIBUTING.md) for details
data/lib/white.rb CHANGED
@@ -2,14 +2,15 @@ require "httparty"
2
2
  require "white/charge"
3
3
  require "white/errors/white_error"
4
4
  require "white/errors/authentication_error"
5
- require "white/errors/card_error"
6
- require "white/errors/invalid_request_error"
5
+ require "white/errors/banking_error"
6
+ require "white/errors/request_error"
7
+ require "white/errors/processing_error"
7
8
 
8
9
  module White
9
10
 
10
11
  include HTTParty
11
12
 
12
- @api_base = 'https://api.whitepayments.com'
13
+ @api_base = 'https://api.whitepayments.com/'
13
14
 
14
15
  def self.api_url(url='')
15
16
  @api_base + url
@@ -17,22 +18,29 @@ module White
17
18
 
18
19
  def self.handle_response(response)
19
20
  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
21
 
27
- if(response.code == 401)
28
- raise White::AuthenticationError.new(body['error']['message'], 422)
22
+ if response.code.between?(200, 299) and !body.key?('error')
23
+ # The request was successful
24
+ return body
29
25
  end
30
26
 
31
- if(response.code >= 500 && response.code < 600)
32
- raise White::WhiteError.new(body['error']['message'], response.code)
27
+ # There was an error .. check the response
28
+ case body['error']['type']
29
+ when 'banking'
30
+ raise White::BankingError.new(body['error']['message'], body['error']['code'], response.code)
31
+
32
+ when 'authentication'
33
+ raise White::AuthenticationError.new(body['error']['message'], body['error']['code'], response.code)
34
+
35
+ when 'processing'
36
+ raise White::ProcessingError.new(body['error']['message'], body['error']['code'], response.code)
37
+
38
+ when 'request'
39
+ raise White::RequestError.new(body['error']['message'], body['error']['code'], response.code)
33
40
  end
34
41
 
35
- body
42
+ # Otherwise, raise a General error
43
+ raise White::WhiteError.new(body['error']['message'], body['error']['code'], response.code)
36
44
  end
37
45
 
38
46
  def self.post(url, body={})
data/lib/white/charge.rb CHANGED
@@ -2,11 +2,11 @@ module White
2
2
  class Charge
3
3
 
4
4
  def self.create(params={})
5
- White.post(White.api_url('/v1/charges'), params)
5
+ White.post(White.api_url('charges/'), params)
6
6
  end
7
7
 
8
8
  def self.all
9
- White.get(White.api_url('/v1/charges'))
9
+ White.get(White.api_url('charges/'))
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,4 @@
1
+ module White
2
+ class BankingError < WhiteError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module White
2
+ class ProcessingError < WhiteError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module White
2
+ class RequestError < WhiteError
3
+ end
4
+ end
@@ -1,15 +1,17 @@
1
1
  module White
2
2
  class WhiteError < StandardError
3
3
  attr_reader :message
4
+ attr_reader :code
4
5
  attr_reader :http_status
5
6
 
6
- def initialize(message=nil, http_status=nil)
7
+ def initialize(message=nil, code=nil, http_status=nil)
7
8
  @message = message
9
+ @code = code
8
10
  @http_status = http_status
9
11
  end
10
12
 
11
13
  def to_s
12
- status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
14
+ status_string = @http_status.nil? ? "" : "(#{@code}Error - Status #{@http_status}) "
13
15
  "#{status_string}#{@message}"
14
16
  end
15
17
  end
data/lib/white/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module White
2
- VERSION = '1.0.0'
2
+ VERSION = '2.0'
3
3
  end
@@ -3,7 +3,7 @@ require_relative '../../spec_helper'
3
3
  describe White::Charge do
4
4
 
5
5
  it "must create a new charge" do
6
- White.api_key = "sk_test_1234567890abcdefghijklmnopq"
6
+ White.api_key = "test_sec_k_25dd497d7e657bb761ad6"
7
7
 
8
8
  response = White::Charge.create(
9
9
  :amount => 400,
@@ -11,13 +11,13 @@ describe White::Charge do
11
11
  :card => {
12
12
  :number => "4242424242424242",
13
13
  :exp_month => 11,
14
- :exp_year => 2014,
15
- :cvv => 123
14
+ :exp_year => 2016,
15
+ :cvc => 123
16
16
  },
17
17
  :description => "Charge for test@example.com"
18
18
  )
19
19
 
20
- response['is_captured'].must_equal true
20
+ response['captured_amount'].must_equal 400
21
21
  end
22
22
 
23
23
  it "must list created charges" do
@@ -10,10 +10,10 @@ describe White::AuthenticationError do
10
10
  :amount => 400,
11
11
  :currency => "usd",
12
12
  :card => {
13
- :number => "3566002020360505",
13
+ :number => "4242424242424242",
14
14
  :exp_month => 11,
15
- :exp_year => 2014,
16
- :cvv => 123
15
+ :exp_year => 2016,
16
+ :cvc => 123
17
17
  },
18
18
  :description => "Charge for test@example.com"
19
19
  )
@@ -0,0 +1,26 @@
1
+ require_relative '../../../spec_helper'
2
+
3
+ describe White::BankingError do
4
+
5
+ it "must be thown with card_declined" do
6
+ White.api_key = "test_sec_k_25dd497d7e657bb761ad6"
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 => 2016,
16
+ :cvc => 123
17
+ },
18
+ :description => "Charge for test@example.com"
19
+ )
20
+ rescue White::BankingError => e
21
+ e.code.must_equal 'card_declined'
22
+ e.http_status.must_equal 402
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,129 @@
1
+ require_relative '../../../spec_helper'
2
+
3
+ describe White::RequestError do
4
+
5
+ # Negative amounts don't raise an error -- TODO: FIX
6
+ #
7
+ # it "must be thown with invalid_request_error" do
8
+ # White.api_key = "test_sec_k_25dd497d7e657bb761ad6"
9
+
10
+ # lambda {
11
+ # response = White::Charge.create(
12
+ # :amount => -1,
13
+ # :currency => "usd",
14
+ # :card => {
15
+ # :number => "4242424242424242",
16
+ # :exp_month => 11,
17
+ # :exp_year => 2016,
18
+ # :cvc => 123
19
+ # },
20
+ # :description => "Charge for test@example.com"
21
+ # )
22
+ # }.must_raise White::RequestError
23
+ # end
24
+
25
+ it "must be thrown with invalid_cvc" do
26
+ White.api_key = "test_sec_k_25dd497d7e657bb761ad6"
27
+
28
+ begin
29
+ response = White::Charge.create(
30
+ :amount => 400,
31
+ :currency => "usd",
32
+ :card => {
33
+ :number => "4242424242424242",
34
+ :exp_month => 11,
35
+ :exp_year => 2016,
36
+ :cvc => "abc"
37
+ },
38
+ :description => "Charge for test@example.com"
39
+ )
40
+ rescue White::RequestError => e
41
+ e.code.must_equal 'unprocessable_entity'
42
+ e.http_status.must_equal 422
43
+ end
44
+ end
45
+
46
+ it "must be thown with expired_card" do
47
+ White.api_key = "test_sec_k_25dd497d7e657bb761ad6"
48
+
49
+ begin
50
+ response = White::Charge.create(
51
+ :amount => 400,
52
+ :currency => "usd",
53
+ :card => {
54
+ :number => "4242424242424242",
55
+ :exp_month => 11,
56
+ :exp_year => 1999,
57
+ :cvc => 123
58
+ },
59
+ :description => "Charge for test@example.com"
60
+ )
61
+ rescue White::RequestError => e
62
+ e.code.must_equal 'unprocessable_entity'
63
+ e.http_status.must_equal 422
64
+ end
65
+ end
66
+
67
+ it "must be thown with invalid_number" do
68
+ White.api_key = "test_sec_k_25dd497d7e657bb761ad6"
69
+
70
+ begin
71
+ response = White::Charge.create(
72
+ :amount => 400,
73
+ :currency => "usd",
74
+ :card => {
75
+ :number => "1234123412341234",
76
+ :exp_month => 11,
77
+ :exp_year => 2016,
78
+ :cvc => 123
79
+ },
80
+ :description => "Charge for test@example.com"
81
+ )
82
+ rescue White::RequestError => e
83
+ e.code.must_equal 'unprocessable_entity'
84
+ e.http_status.must_equal 422
85
+ end
86
+ end
87
+
88
+ it "must be thown with invalid_expiry_month" do
89
+ White.api_key = "test_sec_k_25dd497d7e657bb761ad6"
90
+
91
+ begin
92
+ response = White::Charge.create(
93
+ :amount => 400,
94
+ :currency => "usd",
95
+ :card => {
96
+ :number => "4242424242424242",
97
+ :exp_month => 15,
98
+ :exp_year => 2016,
99
+ :cvc => 123
100
+ },
101
+ :description => "Charge for test@example.com"
102
+ )
103
+ rescue White::RequestError => e
104
+ e.code.must_equal 'unprocessable_entity'
105
+ e.http_status.must_equal 422
106
+ end
107
+ end
108
+
109
+ it "must be thown with invalid_expiry_year" do
110
+ White.api_key = "test_sec_k_25dd497d7e657bb761ad6"
111
+
112
+ begin
113
+ response = White::Charge.create(
114
+ :amount => 400,
115
+ :currency => "usd",
116
+ :card => {
117
+ :number => "4242424242424242",
118
+ :exp_month => 12,
119
+ :exp_year => "abcd",
120
+ :cvc => 123
121
+ },
122
+ :description => "Charge for test@example.com"
123
+ )
124
+ rescue White::RequestError => e
125
+ e.code.must_equal 'unprocessable_entity'
126
+ e.http_status.must_equal 422
127
+ end
128
+ end
129
+ end
@@ -2,21 +2,23 @@ require_relative '../../../spec_helper'
2
2
 
3
3
  describe White::WhiteError do
4
4
 
5
- it "must be thown" do
6
- White.api_key = "sk_test_1234567890abcdefghijklmnopq"
5
+ # Add a test case for a "General Error" -- TODO
6
+ #
7
+ # it "must be thown" do
8
+ # White.api_key = "sk_test_1234567890abcdefghijklmnopq"
7
9
 
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
10
+ # lambda {
11
+ # response = White::Charge.create(
12
+ # :amount => 400,
13
+ # :currency => "usd",
14
+ # :card => {
15
+ # :number => "3566002020360505",
16
+ # :exp_month => 11,
17
+ # :exp_year => 2014,
18
+ # :cvc => 123
19
+ # },
20
+ # :description => "Charge for test@example.com"
21
+ # )
22
+ # }.must_raise White::WhiteError
23
+ # end
22
24
  end
data/white.gemspec CHANGED
@@ -7,7 +7,7 @@ spec = Gem::Specification.new do |s|
7
7
  s.version = White::VERSION
8
8
  s.summary = 'Ruby bindings for the White API'
9
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']
10
+ s.authors = ['Yazin Alirhayim']
11
11
  s.email = ['yazin@whitepayments.com']
12
12
  s.homepage = 'https://whitepayments.com/docs/'
13
13
  s.license = 'MIT'
metadata CHANGED
@@ -1,95 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: white_payments
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: '2.0'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Yazin Alirhayim
9
- - Sebastian Choren
10
8
  autorequire:
11
9
  bindir: bin
12
10
  cert_chain: []
13
- date: 2014-10-20 00:00:00.000000000 Z
11
+ date: 2015-01-17 00:00:00.000000000 Z
14
12
  dependencies:
15
13
  - !ruby/object:Gem::Dependency
16
14
  name: httparty
17
15
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
16
  requirements:
20
- - - ~>
17
+ - - "~>"
21
18
  - !ruby/object:Gem::Version
22
19
  version: '0.13'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
23
  requirements:
28
- - - ~>
24
+ - - "~>"
29
25
  - !ruby/object:Gem::Version
30
26
  version: '0.13'
31
27
  - !ruby/object:Gem::Dependency
32
28
  name: json
33
29
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
30
  requirements:
36
- - - ~>
31
+ - - "~>"
37
32
  - !ruby/object:Gem::Version
38
33
  version: 1.8.1
39
34
  type: :runtime
40
35
  prerelease: false
41
36
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
37
  requirements:
44
- - - ~>
38
+ - - "~>"
45
39
  - !ruby/object:Gem::Version
46
40
  version: 1.8.1
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: minitest
49
43
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
44
  requirements:
52
- - - ~>
45
+ - - "~>"
53
46
  - !ruby/object:Gem::Version
54
47
  version: 4.7.5
55
48
  type: :development
56
49
  prerelease: false
57
50
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
51
  requirements:
60
- - - ~>
52
+ - - "~>"
61
53
  - !ruby/object:Gem::Version
62
54
  version: 4.7.5
63
55
  - !ruby/object:Gem::Dependency
64
56
  name: turn
65
57
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
58
  requirements:
68
- - - ~>
59
+ - - "~>"
69
60
  - !ruby/object:Gem::Version
70
61
  version: 0.9.7
71
62
  type: :development
72
63
  prerelease: false
73
64
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
65
  requirements:
76
- - - ~>
66
+ - - "~>"
77
67
  - !ruby/object:Gem::Version
78
68
  version: 0.9.7
79
69
  - !ruby/object:Gem::Dependency
80
70
  name: rake
81
71
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
72
  requirements:
84
- - - ! '>='
73
+ - - ">="
85
74
  - !ruby/object:Gem::Version
86
75
  version: '0'
87
76
  type: :development
88
77
  prerelease: false
89
78
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
79
  requirements:
92
- - - ! '>='
80
+ - - ">="
93
81
  - !ruby/object:Gem::Version
94
82
  version: '0'
95
83
  description: White is the easiest way to accept payments online in the middle east.
@@ -100,54 +88,55 @@ executables: []
100
88
  extensions: []
101
89
  extra_rdoc_files: []
102
90
  files:
103
- - .gitignore
91
+ - ".gitignore"
104
92
  - Gemfile
105
93
  - Gemfile.lock
106
94
  - LICENSE
95
+ - README.md
107
96
  - Rakefile
108
97
  - lib/white.rb
109
98
  - lib/white/charge.rb
110
99
  - lib/white/errors/authentication_error.rb
111
- - lib/white/errors/card_error.rb
112
- - lib/white/errors/invalid_request_error.rb
100
+ - lib/white/errors/banking_error.rb
101
+ - lib/white/errors/processing_error.rb
102
+ - lib/white/errors/request_error.rb
113
103
  - lib/white/errors/white_error.rb
114
104
  - lib/white/version.rb
115
105
  - 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
106
+ - spec/lib/white/error/authentication_error.rb
107
+ - spec/lib/white/error/banking_error_spec.rb
108
+ - spec/lib/white/error/request_error_spec.rb
119
109
  - spec/lib/white/error/white_error_spec.rb
120
110
  - spec/spec_helper.rb
121
111
  - white.gemspec
122
112
  homepage: https://whitepayments.com/docs/
123
113
  licenses:
124
114
  - MIT
115
+ metadata: {}
125
116
  post_install_message:
126
117
  rdoc_options: []
127
118
  require_paths:
128
119
  - lib
129
120
  required_ruby_version: !ruby/object:Gem::Requirement
130
- none: false
131
121
  requirements:
132
- - - ! '>='
122
+ - - ">="
133
123
  - !ruby/object:Gem::Version
134
124
  version: '0'
135
125
  required_rubygems_version: !ruby/object:Gem::Requirement
136
- none: false
137
126
  requirements:
138
- - - ! '>='
127
+ - - ">="
139
128
  - !ruby/object:Gem::Version
140
129
  version: '0'
141
130
  requirements: []
142
131
  rubyforge_project:
143
- rubygems_version: 1.8.23
132
+ rubygems_version: 2.2.2
144
133
  signing_key:
145
- specification_version: 3
134
+ specification_version: 4
146
135
  summary: Ruby bindings for the White API
147
136
  test_files:
148
137
  - 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
138
+ - spec/lib/white/error/authentication_error.rb
139
+ - spec/lib/white/error/banking_error_spec.rb
140
+ - spec/lib/white/error/request_error_spec.rb
152
141
  - spec/lib/white/error/white_error_spec.rb
153
142
  - spec/spec_helper.rb
@@ -1,11 +0,0 @@
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
@@ -1,4 +0,0 @@
1
- module White
2
- class InvalidRequestError < WhiteError
3
- end
4
- end
@@ -1,151 +0,0 @@
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
@@ -1,22 +0,0 @@
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