Skip to content

Commit

Permalink
Merge pull request #8 from bayonetio/payments/api-flow-changes
Browse files Browse the repository at this point in the history
Payments/api flow changes
  • Loading branch information
imran-arshad authored Mar 5, 2018
2 parents 22960c4 + 3d2cce9 commit dbcc3c5
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 59 deletions.
21 changes: 10 additions & 11 deletions lib/bayonet_client/ecommerce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,35 @@
module BayonetClient

class Ecommerce
def self.consulting(params)
BayonetClient::ApiHelper.request('/consulting', params)
end

def self.feedback(params)
BayonetClient::ApiHelper.request('/feedback', params)
BASE_PATH = "/sigma"

def self.consult(params)
BayonetClient::ApiHelper.request("#{BASE_PATH}/consult", params)
end

def self.feedback_historical(params)
BayonetClient::ApiHelper.request('/feedback-historical', params)
BayonetClient::ApiHelper.request("#{BASE_PATH}/feedback-historical", params)
end

def self.update_transaction(params)
BayonetClient::ApiHelper.request('/update-transaction', params)
BayonetClient::ApiHelper.request("#{BASE_PATH}/update-transaction", params)
end

def self.whitelist(params)
BayonetClient::ApiHelper.request('/labels/whitelist/add', params)
BayonetClient::ApiHelper.request("#{BASE_PATH}/labels/whitelist/add", params)
end

def self.remove_from_whitelist(params)
BayonetClient::ApiHelper.request('/labels/whitelist/remove', params)
BayonetClient::ApiHelper.request("#{BASE_PATH}/labels/whitelist/remove", params)
end

def self.block(params)
BayonetClient::ApiHelper.request('/labels/block/add', params)
BayonetClient::ApiHelper.request("#{BASE_PATH}/labels/block/add", params)
end

def self.remove_from_block(params)
BayonetClient::ApiHelper.request('/labels/block/remove', params)
BayonetClient::ApiHelper.request("#{BASE_PATH}/labels/block/remove", params)
end
end

Expand Down
13 changes: 8 additions & 5 deletions lib/bayonet_client/lending.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@
module BayonetClient

class Lending

BASE_PATH = "/lending"

def self.report_transaction(params)
BayonetClient::ApiHelper.request('/lending/transaction/report', params)
BayonetClient::ApiHelper.request("#{BASE_PATH}/transaction/report", params)
end

def self.report_transaction_and_consult(params)
BayonetClient::ApiHelper.request('/lending/transaction/report?consult=true', params)
BayonetClient::ApiHelper.request("#{BASE_PATH}/transaction/report?consult=true", params)
end

def self.consult(params)
BayonetClient::ApiHelper.request('/lending/consult', params)
BayonetClient::ApiHelper.request("#{BASE_PATH}/consult", params)
end

def self.feedback(params)
BayonetClient::ApiHelper.request('/lending/feedback', params)
BayonetClient::ApiHelper.request("#{BASE_PATH}/feedback", params)
end

def self.feedback_historical(params)
BayonetClient::ApiHelper.request('/lending/feedback-historical', params)
BayonetClient::ApiHelper.request("#{BASE_PATH}/feedback-historical", params)
end
end

Expand Down
11 changes: 4 additions & 7 deletions lib/bayonet_client/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
module BayonetClient

class BayonetResponse
attr_accessor :feedback_api_trans_code, :rules_triggered,
:risk_level, :payload, :reason_code,
attr_accessor :rules_triggered,
:decision, :payload, :reason_code,
:reason_message, :request_body, :bayonet_fingerprint,
:raw

def initialize(parsed_response)

if parsed_response.key?('feedback_api_trans_code')
self.feedback_api_trans_code = parsed_response['feedback_api_trans_code']
end
if parsed_response.key?('rules_triggered')
self.rules_triggered = parsed_response['rules_triggered']
end
if parsed_response.key?('risk_level')
self.risk_level = parsed_response['risk_level']
if parsed_response.key?('decision')
self.decision = parsed_response['decision']
end
if parsed_response.key?('payload')
self.payload = parsed_response['payload']
Expand Down
2 changes: 1 addition & 1 deletion lib/bayonet_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module BayonetClient
VERSION = '2.1.0'
VERSION = '2.1.2'
SUPPORTED_API_VERSIONS = ['2']
end
60 changes: 29 additions & 31 deletions spec/bayonet_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def keys_to_symbols(hash)
end

@invalid_api_key = load_fixture('invalid_api_key')

@params_consulting = keys_to_symbols load_fixture('params_consulting')
@params_feedback = keys_to_symbols load_fixture('params_feedback')
@params_feedback_trans_code = keys_to_symbols load_fixture('params_feedback')
# generate a random transaction id
@transaction_id = (0...8).map { (65 + rand(26)).chr }.join
@params_consult = keys_to_symbols load_fixture('params_consult')
@params_update_transaction = keys_to_symbols load_fixture('params_update_transaction')
@params_feedback_historical = keys_to_symbols load_fixture('params_feedback_historical')
@params_get_fingerprint_data = keys_to_symbols load_fixture('params_get_fingerprint_data')
end
Expand All @@ -45,73 +45,62 @@ def keys_to_symbols(hash)
end
end

describe 'ConsultingEndpoint' do
describe 'ConsultEndpoint' do
it 'should return error on invalid api key' do
BayonetClient.configure(@invalid_api_key, @api_version)
expect{
BayonetClient::Ecommerce.consulting(@params_consulting)
BayonetClient::Ecommerce.consult(@params_consult)
}.to raise_error(BayonetClient::BayonetError)
end

it 'should validate api_key' do
begin
BayonetClient.configure(@invalid_api_key, @api_version)
BayonetClient::Ecommerce.consulting(@params_consulting)
BayonetClient::Ecommerce.consult(@params_consult)
rescue BayonetClient::BayonetError => e
expect(e.reason_code).to eq(12)
end
end

it 'should return success' do
@params_consult[:transaction_id] = @transaction_id
BayonetClient.configure(@api_key, @api_version)
r = BayonetClient::Ecommerce.consulting(@params_consulting)
@params_feedback_trans_code[:feedback_api_trans_code] = r.feedback_api_trans_code
r = BayonetClient::Ecommerce.consult(@params_consult)
expect(r.reason_code).to eq(0)
end

it 'should return feedback_api_trans_code' do
BayonetClient.configure(@api_key, @api_version)
r = BayonetClient::Ecommerce.consulting(@params_consulting)
expect(r.feedback_api_trans_code).to_not be_nil
end
end

describe 'FeedbackEndpoint' do
describe 'TransactionUpdateEndpoint' do
it 'should return error on invalid api key' do
BayonetClient.configure(@invalid_api_key, @api_version)
expect{
BayonetClient::Ecommerce.feedback(@params_feedback)
BayonetClient::Ecommerce.update_transaction(@params_update_transaction)
}.to raise_error(BayonetClient::BayonetError)
end

it 'should validate api_key' do
BayonetClient.configure(@invalid_api_key, @api_version)
begin
BayonetClient::Ecommerce.feedback(@params_feedback)
BayonetClient::Ecommerce.update_transaction(@params_update_transaction)
rescue BayonetClient::BayonetError => e
expect(e.reason_code).to eq(12)
end
end

it 'should return error on invalid feedback api trans code' do
it 'should return error on invalid transaction id' do
# generate a random transaction id
invalid_transaction_id = (0...8).map { (65 + rand(26)).chr }.join
@params_update_transaction[:transaction_id] = invalid_transaction_id
BayonetClient.configure(@api_key, @api_version)
expect{
BayonetClient::Ecommerce.feedback(@params_feedback)
BayonetClient::Ecommerce.update_transaction(@params_update_transaction)
}.to raise_error(BayonetClient::BayonetError)
end

it 'should validate feedback api trans code' do
BayonetClient.configure(@api_key, @api_version)
begin
BayonetClient::Ecommerce.feedback(@params_feedback)
rescue BayonetClient::BayonetError => e
expect(e.reason_code).to eq(87)
end
end

it 'should return success on feedback' do
it 'should return success' do
@params_update_transaction[:transaction_id] = @transaction_id
BayonetClient.configure(@api_key, @api_version)
r = BayonetClient::Ecommerce.feedback(@params_feedback_trans_code)
r = BayonetClient::Ecommerce.update_transaction(@params_update_transaction)
expect(r.reason_code).to eq(0)
end

Expand All @@ -133,6 +122,15 @@ def keys_to_symbols(hash)
expect(e.reason_code).to eq(12)
end
end

it 'should return success' do
# generate a random transaction id
transaction_id = (0...8).map { (65 + rand(26)).chr }.join
@params_feedback_historical[:transaction_id] = transaction_id
BayonetClient.configure(@api_key, @api_version)
r = BayonetClient::Ecommerce.feedback_historical(@params_feedback_historical)
expect(r.reason_code).to eq(0)
end
end

describe 'GetFingerprintDataEndpoint' do
Expand Down
8 changes: 4 additions & 4 deletions spec/fixtures/api_params.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
invalid_api_key: invalid-api-key

params_consulting: {
params_consult: {
email: test_ruby@bayonet.io,
consumer_name: test ruby consumer name,
consumer_internal_id: test_ruby_1,
Expand All @@ -27,6 +27,7 @@ params_consulting: {
},
payment_method: card,
transaction_time: 1476813671,
transaction_id: test_ruby_123,
payment_gateway: stripe,
channel: ecommerce,
coupon: test_ruby_coupon,
Expand All @@ -41,10 +42,9 @@ params_consulting: {
]
}

params_feedback: {
params_update_transaction: {
transaction_status: success,
transaction_id: test_ruby_123,
feedback_api_trans_code: xxx
transaction_id: test_ruby_123
}

params_feedback_historical: {
Expand Down

0 comments on commit dbcc3c5

Please sign in to comment.