payfort_start 0.0.1 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21a5936818d47f37354f17ab24a9844da1456fd2
4
- data.tar.gz: 7af678b629882d5d4be4c9528c1a17a50a41da9b
3
+ metadata.gz: 9994dbb1a740bdcbe93086d2e8684092aa56eaa8
4
+ data.tar.gz: e07d81561889e8c2487eadc8e9dd42cd018d078a
5
5
  SHA512:
6
- metadata.gz: 56f81f4e54b67e62b2f8e132cc3478cc6cac42672419133080e076b335812a2c0c444ef5d04d6e6c00fb8ac9da8145a189c324fa20a65d76b9d490b3ecea9638
7
- data.tar.gz: 35421f2a412b24dd33e9e65a0fe857a48eb0e70e9fd612d4d47fca081208539e4ea485a46c8b521ac2a923d886d4627feb974166878bbd4b101f7831c8109e74
6
+ metadata.gz: 0e62095aa67552e6ae29ee2cb5904504afe81aa0b718a80a9db8da4eec163e83e28bc4a922a22ac278336ea11af7527121fe16402cd9d99165442135aed88ebb
7
+ data.tar.gz: ba7095377e5ba1734d5926860008ba60d3cb26ba4d749ec90f89c01893e986b049e8885d52d26e5e6f9ca0998bbeb869450836bf8f7baedcea4a188a54c5f7fb
data/.gitignore CHANGED
@@ -32,3 +32,4 @@ build/
32
32
 
33
33
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
34
  .rvmrc
35
+ tags
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- payfort (0.1)
4
+ payfort_start (0.0.6)
5
5
  httparty (~> 0.13)
6
6
  json (~> 1.8)
7
7
 
@@ -15,7 +15,7 @@ GEM
15
15
  columnize (0.9.0)
16
16
  debugger-linecache (1.2.0)
17
17
  diff-lcs (1.2.5)
18
- httparty (0.13.5)
18
+ httparty (0.13.7)
19
19
  json (~> 1.8)
20
20
  multi_xml (>= 0.5.2)
21
21
  json (1.8.3)
@@ -40,5 +40,8 @@ PLATFORMS
40
40
 
41
41
  DEPENDENCIES
42
42
  byebug
43
- payfort!
43
+ payfort_start!
44
44
  rspec
45
+
46
+ BUNDLED WITH
47
+ 1.11.2
data/README.md CHANGED
@@ -51,7 +51,7 @@ Start::Charge.create(
51
51
  )
52
52
  ```
53
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://docs.start.payfort.com/testing/).
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://docs.start.payfort.com/guides/testing/).
55
55
 
56
56
  How can you tell that it was successful? Well, if no exception is raised then you're in the clear.
57
57
 
@@ -1,8 +1,10 @@
1
1
  require "httparty"
2
2
  require "start/base_resource"
3
+ require "start/version"
3
4
  require "start/customer"
4
5
  require "start/charge"
5
- require "start/errors/payfort_error"
6
+ require "start/token"
7
+ require "start/errors/start_error"
6
8
  require "start/errors/authentication_error"
7
9
  require "start/errors/banking_error"
8
10
  require "start/errors/request_error"
@@ -15,6 +17,8 @@ module Start
15
17
 
16
18
  ssl_ca_file File.dirname(__FILE__) + '/data/ssl-bundle.crt'
17
19
 
20
+ headers 'User-Agent' => "Start/Ruby/#{Start::VERSION}"
21
+
18
22
  def self.api_key=(value)
19
23
  default_options[:basic_auth] = {username: value, password: ''}
20
24
  end
@@ -8,7 +8,7 @@ module Start
8
8
  end
9
9
 
10
10
  def get(id)
11
- handle_response Start.post("#{path}/#{id}")
11
+ handle_response Start.get("#{path}/#{id}")
12
12
  end
13
13
 
14
14
  def all
@@ -25,23 +25,13 @@ module Start
25
25
  return body
26
26
  end
27
27
 
28
- # There was an error .. check the response
29
- case body['error']['type']
30
- when 'banking'
31
- raise Start::BankingError.new(body['error']['message'], body['error']['code'], response.code)
28
+ exception_class = if ['banking', 'authentication', 'processing', 'request'].include?(body['error']['type'])
29
+ Object.const_get "Start::#{body['error']['type'].capitalize}Error"
30
+ else
31
+ StartError
32
+ end
32
33
 
33
- when 'authentication'
34
- raise Start::AuthenticationError.new(body['error']['message'], body['error']['code'], response.code)
35
-
36
- when 'processing'
37
- raise Start::ProcessingError.new(body['error']['message'], body['error']['code'], response.code)
38
-
39
- when 'request'
40
- raise Start::RequestError.new(body['error']['message'], body['error']['code'], response.code)
41
- end
42
-
43
- # Otherwise, raise a General error
44
- raise Start::StartError.new(body['error']['message'], body['error']['code'], response.code)
34
+ raise exception_class.new(body['error']['message'], body['error']['code'], response.code, body['error']['extras'])
45
35
  end
46
36
  end
47
37
  end
@@ -1,13 +1,12 @@
1
1
  module Start
2
2
  class StartError < StandardError
3
- attr_reader :message
4
- attr_reader :code
5
- attr_reader :http_status
3
+ attr_reader :message, :code, :http_status, :extras
6
4
 
7
- def initialize(message=nil, code=nil, http_status=nil)
5
+ def initialize(message = nil, code = nil, http_status = nil, extras = {})
8
6
  @message = message
9
7
  @code = code
10
8
  @http_status = http_status
9
+ @extras = extras
11
10
  end
12
11
 
13
12
  def to_s
@@ -0,0 +1,5 @@
1
+ module Start
2
+ class Token < BaseResource
3
+ self.path = '/tokens'
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Start
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -23,6 +23,30 @@ describe Start::Charge do
23
23
  expect(response['captured_amount']).to eq(400)
24
24
  end
25
25
 
26
+ context 'when metadata parameter is passed' do
27
+ it 'creates charge with metadata' do
28
+ response = Start::Charge.create(
29
+ :amount => 400,
30
+ :currency => "usd",
31
+ :email => "ahmed@example.com",
32
+ :card => {
33
+ :name => "Abdullah Ahmed",
34
+ :number => "4242424242424242",
35
+ :exp_month => 11,
36
+ :exp_year => 2016,
37
+ :cvc => 123
38
+ },
39
+ :description => "Charge for test@example.com",
40
+ :metadata => {
41
+ :reference_id => "12334567890",
42
+ :tag => "new"
43
+ }
44
+ )
45
+
46
+ expect(response['metadata']).to eq({"reference_id"=>"12334567890", "tag"=>"new"})
47
+ end
48
+ end
49
+
26
50
  it "must list created charges" do
27
51
  response = Start::Charge.all()
28
52
 
@@ -21,6 +21,7 @@ describe Start::BankingError do
21
21
  rescue Start::BankingError => e
22
22
  expect(e.code).to eq('card_declined')
23
23
  expect(e.http_status).to eq(402)
24
+ expect(e.extras).to include('charge')
24
25
  end
25
26
  end
26
27
  end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Start::Token do
4
+ before do
5
+ Start.api_key = "test_open_k_d93727030f5ae0e5ff73"
6
+ end
7
+
8
+ it "must create a new token" do
9
+ response = Start::Token.create(
10
+ :number => "4242424242424242",
11
+ :exp_month => 11,
12
+ :exp_year => 2016,
13
+ :cvc => 123
14
+ )
15
+
16
+ expect(response['id']).to start_with('tok_')
17
+ end
18
+
19
+ context 'when holder name is passed' do
20
+ it "must create a card with holder name" do
21
+ response = Start::Token.create(
22
+ :number => "4242424242424242",
23
+ :exp_month => 11,
24
+ :exp_year => 2016,
25
+ :cvc => 123,
26
+ :name => "Abdullah Mohammed"
27
+ )
28
+
29
+ expect(response['card']['name']).to eq('Abdullah Mohammed')
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payfort_start
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Gabriel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-22 00:00:00.000000000 Z
12
+ date: 2016-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -61,9 +61,10 @@ files:
61
61
  - lib/start/customer.rb
62
62
  - lib/start/errors/authentication_error.rb
63
63
  - lib/start/errors/banking_error.rb
64
- - lib/start/errors/payfort_error.rb
65
64
  - lib/start/errors/processing_error.rb
66
65
  - lib/start/errors/request_error.rb
66
+ - lib/start/errors/start_error.rb
67
+ - lib/start/token.rb
67
68
  - lib/start/version.rb
68
69
  - payfort_start.gemspec
69
70
  - spec/lib/start/charge_spec.rb
@@ -71,6 +72,7 @@ files:
71
72
  - spec/lib/start/error/authentication_error_spec.rb
72
73
  - spec/lib/start/error/banking_error_spec.rb
73
74
  - spec/lib/start/error/request_error_spec.rb
75
+ - spec/lib/start/token_spec.rb
74
76
  - spec/spec_helper.rb
75
77
  homepage: https://start.payfort.com/docs/
76
78
  licenses:
@@ -92,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
94
  version: '0'
93
95
  requirements: []
94
96
  rubyforge_project:
95
- rubygems_version: 2.4.6
97
+ rubygems_version: 2.5.1
96
98
  signing_key:
97
99
  specification_version: 4
98
100
  summary: Ruby bindings for the Payfort Start API
@@ -102,4 +104,5 @@ test_files:
102
104
  - spec/lib/start/error/authentication_error_spec.rb
103
105
  - spec/lib/start/error/banking_error_spec.rb
104
106
  - spec/lib/start/error/request_error_spec.rb
107
+ - spec/lib/start/token_spec.rb
105
108
  - spec/spec_helper.rb