-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from internetee/add-oneoff-endpoint-for-payment
added oneoff feature for payment
- Loading branch information
Showing
15 changed files
with
249 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,3 +90,6 @@ group :test do | |
gem 'webdrivers' | ||
gem 'webmock' | ||
end | ||
|
||
# token | ||
gem 'jwt' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Billing | ||
module Connection | ||
BASE_URL = Rails.configuration.customization[:eis_billing_system_base_url] | ||
INITIATOR = 'registry'.freeze | ||
|
||
def connection | ||
Faraday.new(options) do |faraday| | ||
faraday.adapter Faraday.default_adapter | ||
end | ||
end | ||
|
||
private | ||
|
||
def options | ||
{ | ||
headers: { | ||
'Authorization' => "Bearer #{generate_token}", | ||
'Content-Type' => 'application/json', | ||
}, | ||
url: BASE_URL, | ||
} | ||
end | ||
|
||
def generate_token | ||
JWT.encode(payload, billing_secret) | ||
end | ||
|
||
def payload | ||
{ initiator: INITIATOR } | ||
end | ||
|
||
def billing_secret | ||
Rails.configuration.customization[:billing_secret] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Billing | ||
class Oneoff | ||
include Billing::Request | ||
attr_reader :invoice_number, :customer_url, :reference_number | ||
|
||
def initialize(invoice_number:, customer_url:, reference_number:) | ||
@invoice_number = invoice_number | ||
@customer_url = customer_url | ||
@reference_number = reference_number | ||
end | ||
|
||
def self.send_invoice(invoice_number:, customer_url:, reference_number:) | ||
fetcher = new(invoice_number: invoice_number, customer_url: customer_url, reference_number: reference_number) | ||
fetcher.send_it | ||
end | ||
|
||
def send_it | ||
post invoice_oneoff_url, params | ||
end | ||
|
||
def params | ||
{ invoice_number: invoice_number, | ||
customer_url: customer_url, | ||
reference_number: reference_number } | ||
end | ||
|
||
def invoice_oneoff_url | ||
'/api/v1/invoice_generator/oneoff' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Billing | ||
module Request | ||
include Billing::Connection | ||
|
||
def get(path, params = {}) | ||
respond_with( | ||
connection.get(path, params) | ||
) | ||
end | ||
|
||
def post(path, params = {}) | ||
respond_with( | ||
connection.post(path, JSON.dump(params)) | ||
) | ||
end | ||
|
||
private | ||
|
||
def respond_with(response) | ||
JSON.parse response.body | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Billing | ||
class SendCallback | ||
include Billing::Request | ||
attr_reader :reference_number | ||
|
||
def initialize(reference_number:) | ||
@reference_number = reference_number | ||
end | ||
|
||
def self.send(reference_number:) | ||
fetcher = new(reference_number: reference_number) | ||
fetcher.send_it | ||
end | ||
|
||
def send_it | ||
get billing_callback_url | ||
end | ||
|
||
def billing_callback_url | ||
"/api/v1/callback_handler/callback?payment_reference=#{reference_number}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'webmock/rspec' | ||
|
||
RSpec.describe Billing::Oneoff do | ||
before(:each) do | ||
VCR.eject_cassette | ||
end | ||
|
||
specify "#send invoice" do | ||
stub_request(:post, "#{Billing::Connection::BASE_URL}/api/v1/invoice_generator/oneoff") | ||
.to_return(status: 200, body: "{\"oneoff_redirect_link\": \"everypay/go\"}", headers: {}) | ||
|
||
response = described_class.send_invoice(invoice_number: '332211', customer_url: 'http://fake.ee', reference_number: '33322') | ||
|
||
expect(response["oneoff_redirect_link"].to_s).to eq("everypay/go") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'webmock/rspec' | ||
|
||
RSpec.describe Billing::SendCallback do | ||
before(:each) do | ||
VCR.eject_cassette | ||
end | ||
|
||
specify "#send callback" do | ||
stub_request(:get, "#{Billing::Connection::BASE_URL}/api/v1/callback_handler/callback?payment_reference=3434sdfsdfsdf2234234") | ||
.to_return(status: 200, body: "{\"message\": \"received\"}", headers: {}) | ||
|
||
response = described_class.send(reference_number: '3434sdfsdfsdf2234234') | ||
|
||
expect(response["message"].to_s).to eq("received") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters