Skip to content

Commit

Permalink
feat (payment-url): add support for invoice payment url (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovrocolic authored Feb 12, 2024
1 parent 5ad5301 commit 205363a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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

0 comments on commit 205363a

Please sign in to comment.