payfort 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 +7 -0
- data/.gitignore +34 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +31 -0
- data/LICENSE +21 -0
- data/README.md +95 -0
- data/Rakefile +8 -0
- data/lib/payfort.rb +65 -0
- data/lib/payfort/charge.rb +17 -0
- data/lib/payfort/customer.rb +17 -0
- data/lib/payfort/errors/authentication_error.rb +4 -0
- data/lib/payfort/errors/banking_error.rb +4 -0
- data/lib/payfort/errors/payfort_error.rb +18 -0
- data/lib/payfort/errors/processing_error.rb +4 -0
- data/lib/payfort/errors/request_error.rb +4 -0
- data/lib/payfort/version.rb +3 -0
- data/payfort.gemspec +25 -0
- data/spec/lib/white/charge_spec.rb +30 -0
- data/spec/lib/white/customer_spec.rb +29 -0
- data/spec/lib/white/error/authentication_error.rb +22 -0
- data/spec/lib/white/error/banking_error_spec.rb +28 -0
- data/spec/lib/white/error/request_error_spec.rb +129 -0
- data/spec/lib/white/error/white_error_spec.rb +24 -0
- data/spec/spec_helper.rb +8 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 89a03ad1cd448b6a1421b5802e9ea3580b34bf56
|
4
|
+
data.tar.gz: baca6b8a6e67fa85a18aa4b90e82330047d2444b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5ad5dd359b2fe9c7af3ed1946900015904cc0eb9f24c82bd9bc58a052160a972e6be964d63609e3e93c1d4c801eb133c37f9930a7dd44d8300bce030db6515cd
|
7
|
+
data.tar.gz: 0ee2753efdda3a83ee1959a6bc7c334b35058ec6b6c7fdff483dba74e8dfa65e0693a0440e2c55a8a3633f1d8b2e57ef8c8c045dacd9225a1d937809688bd083
|
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
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
white_payments (2.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_payments!
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Payfort
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
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 'payfort', require: 'payfort'
|
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 'payfort'
|
27
|
+
|
28
|
+
Payfort.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
|
+
:email => "customer@example.com",
|
44
|
+
:card => {
|
45
|
+
:number => "4242424242424242",
|
46
|
+
:exp_month => 11,
|
47
|
+
:exp_year => 2016,
|
48
|
+
:cvv => 123
|
49
|
+
},
|
50
|
+
:description => "2kg of lizard tails, non-refundable"
|
51
|
+
)
|
52
|
+
```
|
53
|
+
|
54
|
+
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/).
|
55
|
+
|
56
|
+
How can you tell that it was successful? Well, if no exception is raised then you're in the clear.
|
57
|
+
|
58
|
+
### 3. Handling Errors
|
59
|
+
|
60
|
+
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:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
begin
|
64
|
+
# Use White's bindings...
|
65
|
+
|
66
|
+
rescue White::BankingError => e
|
67
|
+
# Since it's a decline, White::BankingError will be caught
|
68
|
+
puts "Status is: #{e.http_status}"
|
69
|
+
puts "Code is: #{e.code}"
|
70
|
+
puts "Message is: #{e.message}"
|
71
|
+
|
72
|
+
rescue White::RequestError => e
|
73
|
+
# Invalid parameters were supplied to White's API
|
74
|
+
|
75
|
+
rescue White::AuthenticationError => e
|
76
|
+
# There's something wrong with that API key you passed
|
77
|
+
|
78
|
+
rescue White::ProcessingError => e
|
79
|
+
# There's something wrong on White's end
|
80
|
+
|
81
|
+
rescue White::WhiteError => e
|
82
|
+
# Display a very generic error to the user, and maybe send
|
83
|
+
# yourself an email
|
84
|
+
|
85
|
+
rescue => e
|
86
|
+
# Something else happened, completely unrelated to White
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
## Testing White
|
91
|
+
If you're looking to contribute to White, then grab this repo and run `rake` on your local machine to run the unit tests.
|
92
|
+
|
93
|
+
## Contributing
|
94
|
+
|
95
|
+
Read our [Contributing Guidelines](CONTRIBUTING.md) for details
|
data/Rakefile
ADDED
data/lib/payfort.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "payfort/customer"
|
3
|
+
require "payfort/charge"
|
4
|
+
require "payfort/errors/payfort_error"
|
5
|
+
require "payfort/errors/authentication_error"
|
6
|
+
require "payfort/errors/banking_error"
|
7
|
+
require "payfort/errors/request_error"
|
8
|
+
require "payfort/errors/processing_error"
|
9
|
+
|
10
|
+
module Payfort
|
11
|
+
|
12
|
+
include HTTParty
|
13
|
+
|
14
|
+
@api_base = 'https://api.start.payfort.com/'
|
15
|
+
|
16
|
+
def self.api_url(url='')
|
17
|
+
@api_base + url
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.handle_response(response)
|
21
|
+
body = JSON.parse(response.body);
|
22
|
+
|
23
|
+
if response.code.between?(200, 299) and !body.key?('error')
|
24
|
+
# The request was successful
|
25
|
+
return body
|
26
|
+
end
|
27
|
+
|
28
|
+
# There was an error .. check the response
|
29
|
+
case body['error']['type']
|
30
|
+
when 'banking'
|
31
|
+
raise Payfort::BankingError.new(body['error']['message'], body['error']['code'], response.code)
|
32
|
+
|
33
|
+
when 'authentication'
|
34
|
+
raise Payfort::AuthenticationError.new(body['error']['message'], body['error']['code'], response.code)
|
35
|
+
|
36
|
+
when 'processing'
|
37
|
+
raise Payfort::ProcessingError.new(body['error']['message'], body['error']['code'], response.code)
|
38
|
+
|
39
|
+
when 'request'
|
40
|
+
raise Payfort::RequestError.new(body['error']['message'], body['error']['code'], response.code)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Otherwise, raise a General error
|
44
|
+
raise Payfort::PayfortError.new(body['error']['message'], body['error']['code'], response.code)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.post(url, body={})
|
48
|
+
options = {basic_auth: {username: api_key, password: ''}}
|
49
|
+
options.merge!({body: body})
|
50
|
+
response = HTTParty.post(url, options)
|
51
|
+
self.handle_response(response)
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.get(url, query={})
|
56
|
+
options = {basic_auth: {username: api_key, password: ''}}
|
57
|
+
options.merge!({query: query})
|
58
|
+
response = HTTParty.get(url, options)
|
59
|
+
JSON.parse(response.body);
|
60
|
+
end
|
61
|
+
|
62
|
+
class << self
|
63
|
+
attr_accessor :api_key
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Payfort
|
2
|
+
class Charge
|
3
|
+
|
4
|
+
def self.create(params={})
|
5
|
+
Payfort.post(Payfort.api_url('charges/'), params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.get(id)
|
9
|
+
Payfort.get(Payfort.api_url('charges/' + id.to_s))
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.all
|
13
|
+
Payfort.get(Payfort.api_url('charges/'))
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Payfort
|
2
|
+
class Customer
|
3
|
+
|
4
|
+
def self.create(params={})
|
5
|
+
Payfort.post(Payfort.api_url('customers/'), params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.get(id)
|
9
|
+
Payfort.get(Payfort.api_url('customers/' + id.to_s))
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.all
|
13
|
+
Payfort.get(Payfort.api_url('customers/'))
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Payfort
|
2
|
+
class PayfortError < StandardError
|
3
|
+
attr_reader :message
|
4
|
+
attr_reader :code
|
5
|
+
attr_reader :http_status
|
6
|
+
|
7
|
+
def initialize(message=nil, code=nil, http_status=nil)
|
8
|
+
@message = message
|
9
|
+
@code = code
|
10
|
+
@http_status = http_status
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
status_string = @http_status.nil? ? "" : "(#{@code}Error - Status #{@http_status}) "
|
15
|
+
"#{status_string}#{@message}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/payfort.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
2
|
+
|
3
|
+
require 'payfort/version'
|
4
|
+
|
5
|
+
spec = Gem::Specification.new do |s|
|
6
|
+
s.name = 'payfort'
|
7
|
+
s.version = Payfort::VERSION
|
8
|
+
s.summary = 'Ruby bindings for the Payfort Start API'
|
9
|
+
s.description = 'Payfort Start is the easiest way to accept payments online in the middle east. See https://start.payfort.com for details.'
|
10
|
+
s.authors = ['Pavel Gabriel','Yazin Alirhayim']
|
11
|
+
s.email = ['pavel@payfort.com','yazin@payfort.com']
|
12
|
+
s.homepage = 'https://start.payfort.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
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe White::Charge do
|
4
|
+
|
5
|
+
it "must create a new charge" do
|
6
|
+
White.api_key = "test_sec_k_25dd497d7e657bb761ad6"
|
7
|
+
|
8
|
+
response = White::Charge.create(
|
9
|
+
:amount => 400,
|
10
|
+
:currency => "usd",
|
11
|
+
:email => "ahmed@example.com",
|
12
|
+
:card => {
|
13
|
+
:name => "Abdullah Ahmed",
|
14
|
+
:number => "4242424242424242",
|
15
|
+
:exp_month => 11,
|
16
|
+
:exp_year => 2016,
|
17
|
+
:cvc => 123
|
18
|
+
},
|
19
|
+
:description => "Charge for test@example.com"
|
20
|
+
)
|
21
|
+
|
22
|
+
response['captured_amount'].must_equal 400
|
23
|
+
end
|
24
|
+
|
25
|
+
it "must list created charges" do
|
26
|
+
response = White::Charge.all()
|
27
|
+
response.wont_be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
# require_relative '../../../lib/white/customer'
|
3
|
+
|
4
|
+
describe White::Customer do
|
5
|
+
|
6
|
+
it "must create a new customer" do
|
7
|
+
White.api_key = "test_sec_k_25dd497d7e657bb761ad6"
|
8
|
+
|
9
|
+
response = White::Customer.create(
|
10
|
+
:name => "Abdullah Ahmed",
|
11
|
+
:email => "abdullah@msn.com",
|
12
|
+
:card => {
|
13
|
+
:number => "4242424242424242",
|
14
|
+
:exp_month => 11,
|
15
|
+
:exp_year => 2016,
|
16
|
+
:cvc => 123
|
17
|
+
},
|
18
|
+
:description => "Signed up at the Trade Show in Dec 2014"
|
19
|
+
)
|
20
|
+
|
21
|
+
response['name'].must_equal "Abdullah Ahmed"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "must list created customers" do
|
25
|
+
response = White::Customer.all()
|
26
|
+
response.wont_be_empty
|
27
|
+
end
|
28
|
+
|
29
|
+
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 => "4242424242424242",
|
14
|
+
:exp_month => 11,
|
15
|
+
:exp_year => 2016,
|
16
|
+
:cvc => 123
|
17
|
+
},
|
18
|
+
:description => "Charge for test@example.com"
|
19
|
+
)
|
20
|
+
}.must_raise White::AuthenticationError
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
:email => "abdullah@msn.com",
|
13
|
+
:card => {
|
14
|
+
:name => "Abdullah Ahmed",
|
15
|
+
:number => "4000000000000002",
|
16
|
+
:exp_month => 11,
|
17
|
+
:exp_year => 2016,
|
18
|
+
:cvc => 123
|
19
|
+
},
|
20
|
+
:description => "Charge for test@example.com"
|
21
|
+
)
|
22
|
+
rescue White::BankingError => e
|
23
|
+
e.code.must_equal 'card_declined'
|
24
|
+
e.http_status.must_equal 402
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
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
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
|
3
|
+
describe White::WhiteError do
|
4
|
+
|
5
|
+
# Add a test case for a "General Error" -- TODO
|
6
|
+
#
|
7
|
+
# it "must be thown" do
|
8
|
+
# White.api_key = "sk_test_1234567890abcdefghijklmnopq"
|
9
|
+
|
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
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: payfort
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pavel Gabriel
|
8
|
+
- Yazin Alirhayim
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-08-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.13'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.13'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: json
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.8.1
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.8.1
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 4.7.5
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 4.7.5
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: turn
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.9.7
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.9.7
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description: Payfort Start is the easiest way to accept payments online in the middle
|
85
|
+
east. See https://start.payfort.com for details.
|
86
|
+
email:
|
87
|
+
- pavel@payfort.com
|
88
|
+
- yazin@payfort.com
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- ".gitignore"
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- lib/payfort.rb
|
100
|
+
- lib/payfort/charge.rb
|
101
|
+
- lib/payfort/customer.rb
|
102
|
+
- lib/payfort/errors/authentication_error.rb
|
103
|
+
- lib/payfort/errors/banking_error.rb
|
104
|
+
- lib/payfort/errors/payfort_error.rb
|
105
|
+
- lib/payfort/errors/processing_error.rb
|
106
|
+
- lib/payfort/errors/request_error.rb
|
107
|
+
- lib/payfort/version.rb
|
108
|
+
- payfort.gemspec
|
109
|
+
- spec/lib/white/charge_spec.rb
|
110
|
+
- spec/lib/white/customer_spec.rb
|
111
|
+
- spec/lib/white/error/authentication_error.rb
|
112
|
+
- spec/lib/white/error/banking_error_spec.rb
|
113
|
+
- spec/lib/white/error/request_error_spec.rb
|
114
|
+
- spec/lib/white/error/white_error_spec.rb
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
homepage: https://start.payfort.com/docs/
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.4.6
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Ruby bindings for the Payfort Start API
|
140
|
+
test_files:
|
141
|
+
- spec/lib/white/charge_spec.rb
|
142
|
+
- spec/lib/white/customer_spec.rb
|
143
|
+
- spec/lib/white/error/authentication_error.rb
|
144
|
+
- spec/lib/white/error/banking_error_spec.rb
|
145
|
+
- spec/lib/white/error/request_error_spec.rb
|
146
|
+
- spec/lib/white/error/white_error_spec.rb
|
147
|
+
- spec/spec_helper.rb
|