Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat (invoice-payment-url): add support for invoice payment url #172

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/lago/api/resources/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def retry_payment(invoice_id)
JSON.parse(response.to_json, object_class: OpenStruct)
end

def payment_url(invoice_id)
path = "/api/v1/invoices/#{invoice_id}/payment_url"
response = connection.post({}, path)['invoice_payment_details']

JSON.parse(response.to_json, object_class: OpenStruct)
end

def whitelist_params(params)
result = {
payment_status: params[:payment_status],
Expand Down
22 changes: 22 additions & 0 deletions spec/lago/api/resources/invoice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,26 @@
expect(result).to eq(true)
end
end

describe '#payment_url' do
let(:url_response) do
{
'invoice_payment_details' => {
'payment_url' => 'https://example.com',
}
}.to_json
end

before do
stub_request(:post, "https://api.getlago.com/api/v1/invoices/#{invoice_id}/payment_url")
.with(body: {})
.to_return(body: url_response, status: 200)
end

it 'returns payment url' do
result = resource.payment_url(invoice_id)

expect(result.payment_url).to eq('https://example.com')
end
end
end
Loading