Skip to content

Commit 0504351

Browse files
authored
Merge pull request #9 from stoffus/refactoring-with-docs-updates
Refactoring with docs updates
2 parents 61fca58 + 9614e02 commit 0504351

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

README.md

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Payson API
22

3-
A simple utility to handle requests against the Payson payment gateway API.
3+
A zero dependency, pure Ruby utility to handle requests against the Payson payment gateway API.
44

55
## Supported Ruby versions
66

77
* 2.6
88
* 2.7
99
* 3.0
1010

11-
## Install
11+
## Installation
1212

1313
Put this line in your Gemfile:
1414

@@ -58,6 +58,10 @@ request.order.items << PaysonAPI::V2::Requests::OrderItem.new.tap do |item|
5858
item.quantity = 3
5959
item.reference = 'product-1'
6060
end
61+
62+
checkout = PaysonAPI::V2::Client.create_checkout(request)
63+
64+
# Continue by rendering the HTML from checkout.snippet.
6165
```
6266

6367
### Updating a checkout
@@ -116,8 +120,6 @@ payment.return_url = 'http://localhost/payson/success'
116120
payment.cancel_url = 'http://localhost/payson/cancel'
117121
payment.ipn_url = 'http://localhost/payson/ipn'
118122
payment.memo = 'Sample order description'
119-
payment.sender = sender
120-
121123
payment.sender = PaysonAPI::V1::Sender.new.tap do |s|
122124
s.email = '[email protected]'
123125
s.first_name = 'My'
@@ -197,10 +199,10 @@ class Payson < ApplicationController
197199
# Create a new IPN request object containing the raw response from above
198200
ipn_request = PaysonAPI::V1::Requests::IPN.new(ipn_response.raw)
199201

200-
validate = PaysonAPI::V1::Client.validate_ipn(ipn_request)
202+
validation = PaysonAPI::V1::Client.validate_ipn(ipn_request)
201203

202-
unless validate.verified?
203-
raise "Something went terribly wrong."
204+
unless validation.verified?
205+
raise "Something went terribly wrong"
204206
end
205207

206208
# Do business transactions, e.g. update the corresponding order:
@@ -213,15 +215,15 @@ end
213215

214216
## Todo
215217

216-
Document the code for the Payson Checkout v2 processes.
218+
Nothing at the moment.
217219

218-
## Build Status
220+
## Project Status
219221

220-
[![Build Status](https://travis-ci.org/stoffus/payson_api.svg?branch=master)](https://travis-ci.org/stoffus/payson_api)
222+
[![Build Status](https://travis-ci.org/stoffus/payson_api.svg?branch=master)](https://travis-ci.org/stoffus/payson_api) [![Gem Version](https://badge.fury.io/rb/payson_api.svg)](https://badge.fury.io/rb/payson_api)
221223

222224
## Questions, Feedback
223225

224-
Feel free to message me on Github (stoffus).
226+
Feel free to message me on [GitHub](https://github.com/stoffus).
225227

226228
## Copyright
227229

lib/payson_api/v2/client.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ def self.get_checkout(id)
1818

1919
def self.create_checkout(request)
2020
response = payson_request(Net::HTTP::Post, PAYSON_API_RESOURCES[:checkouts][:create], request)
21-
handle_validation_error(response)
21+
intercept_validation_errors(response)
2222
PaysonAPI::V2::Models::Checkout.from_hash(JSON.parse(response.body))
2323
end
2424

2525
def self.update_checkout(request)
2626
response = payson_request(Net::HTTP::Put, PAYSON_API_RESOURCES[:checkouts][:update] % request.id, request)
27-
handle_validation_error(response)
27+
intercept_validation_errors(response)
2828
PaysonAPI::V2::Models::Checkout.from_hash(JSON.parse(response.body))
2929
end
3030

@@ -38,7 +38,7 @@ def self.list_checkouts(request)
3838
end
3939
end
4040

41-
def self.handle_validation_error(response)
41+
def self.intercept_validation_errors(response)
4242
if response.code == '400' || response.code == '500' # rubocop:disable Style/GuardClause
4343
raise PaysonAPI::V2::Errors::ValidationError, errors: JSON.parse(response.body)['errors']
4444
end
@@ -62,6 +62,8 @@ def self.payson_request(method, resource, request = nil)
6262

6363
response
6464
end
65+
66+
private_class_method :intercept_validation_errors, :hash_to_params, :payson_request
6567
end
6668
end
6769
end

lib/payson_api/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module PaysonAPI
4-
VERSION = '1.0.0'
4+
VERSION = '1.0.2'
55
end

0 commit comments

Comments
 (0)