Skip to content

Commit

Permalink
Add Receipt API (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
som-m committed Feb 11, 2021
1 parent a07a263 commit 6f943de
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/omise/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require "omise/integration"
require "omise/link"
require "omise/occurrence"
require "omise/receipt"
require "omise/recipient"
require "omise/refund"
require "omise/search"
Expand Down
20 changes: 20 additions & 0 deletions lib/omise/receipt.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "omise/object"
require "omise/list"

module Omise
class Receipt < OmiseObject
self.endpoint = "/receipts"

def self.retrieve(id, attributes = {})
new resource(location(id), attributes).get(attributes)
end

def self.list(attributes = {})
List.new resource(location, attributes).get(attributes)
end

def reload(attributes = {})
assign_attributes resource(attributes).get(attributes)
end
end
end
90 changes: 90 additions & 0 deletions test/fixtures/api.omise.co/receipts-get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"object": "receipt_list",
"data": [
{
"object": "receipt",
"id": "rcpt_5lrm8qjcaj5vpu2790m",
"livemode": true,
"location": "/receipts/rcpt_5lrm8qjcaj5vpu2790m",
"credit_note": false,
"charge_fee": 7,
"subtotal": 7,
"transfer_fee": 0,
"voided_fee": 0,
"vat": 0,
"wht": 0,
"total": 7,
"company_address": "123 The Road, Thailand",
"company_name": "Omise",
"company_tax_id": "0123456789012",
"currency": "THB",
"customer_address": "456 The Street, Singapore",
"customer_email": "john.doe@omise.co",
"customer_name": "John Doe",
"customer_statement_name": "John Doe",
"customer_tax_id": "10000",
"number": "OMTH202011050018",
"created_at": "2020-11-05T18:02:05Z",
"issued_on": "2020-11-05",
"adjustment_transaction": {
"object": "transaction",
"id": "trxn_5lrm8qjiaye00x5dv4r",
"livemode": true,
"currency": "THB",
"amount": 0,
"location": "/transactions/trxn_5lrm8qjiaye00x5dv4r",
"direction": "credit",
"key": "receipt.vat_adjustment.credit",
"origin": "rcpt_5lrm8qjcaj5vpu2790m",
"transferable_at": "2020-11-05T18:02:05Z",
"created_at": "2020-11-05T18:02:05Z"
}
},
{
"object": "receipt",
"id": "rcpt_5ls0b8zb53qmw3mlvfz",
"livemode": true,
"location": "/receipts/rcpt_5ls0b8zb53qmw3mlvfz",
"credit_note": false,
"charge_fee": 7,
"subtotal": 7,
"transfer_fee": 0,
"voided_fee": 0,
"vat": 0,
"wht": 0,
"total": 7,
"company_address": "123 The Road, Thailand",
"company_name": "Omise",
"company_tax_id": "0123456789012",
"currency": "THB",
"customer_address": "456 The Street, Singapore",
"customer_email": "john.doe@omise.co",
"customer_name": "John Doe",
"customer_statement_name": "John Doe",
"customer_tax_id": "10000",
"number": "OMTH202011050019",
"created_at": "2020-11-05T18:02:05Z",
"issued_on": "2020-11-05",
"adjustment_transaction": {
"object": "transaction",
"id": "trxn_5ls0b8zftdzm5vw90d6",
"livemode": true,
"currency": "THB",
"amount": 0,
"location": "/transactions/trxn_5ls0b8zftdzm5vw90d6",
"direction": "credit",
"key": "receipt.vat_adjustment.credit",
"origin": "rcpt_5ls0b8zb53qmw3mlvfz",
"transferable_at": "2020-11-05T18:02:05Z",
"created_at": "2020-11-05T18:02:05Z"
}
}
],
"limit": 20,
"offset": 0,
"total": 2,
"location": "/receipts",
"order": "chronological",
"from": "1970-01-01T00:00:00Z",
"to": "2021-02-07T23:59:59Z"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"object": "receipt",
"id": "rcpt_5ls0b8zb53qmw3mlvfz",
"livemode": true,
"location": "/receipts/rcpt_5ls0b8zb53qmw3mlvfz",
"credit_note": false,
"charge_fee": 7,
"subtotal": 7,
"transfer_fee": 0,
"voided_fee": 0,
"vat": 0,
"wht": 0,
"total": 7,
"company_address": "123 The Road, Thailand",
"company_name": "Omise",
"company_tax_id": "0123456789012",
"currency": "THB",
"customer_address": "456 The Street, Singapore",
"customer_email": "john.doe@omise.co",
"customer_name": "John Doe",
"customer_statement_name": "John Doe",
"customer_tax_id": "10000",
"number": "OMTH202011050019",
"created_at": "2020-11-05T18:02:05Z",
"issued_on": "2020-11-05",
"adjustment_transaction": {
"object": "transaction",
"id": "trxn_5ls0b8zftdzm5vw90d6",
"livemode": true,
"currency": "THB",
"amount": 0,
"location": "/transactions/trxn_5ls0b8zftdzm5vw90d6",
"direction": "credit",
"key": "receipt.vat_adjustment.credit",
"origin": "rcpt_5ls0b8zb53qmw3mlvfz",
"transferable_at": "2020-11-05T18:02:05Z",
"created_at": "2020-11-05T18:02:05Z"
}
}
29 changes: 29 additions & 0 deletions test/omise/test_receipt.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "support"

class TestReceipt < Omise::Test
setup do
@receipt = Omise::Receipt.retrieve("rcpt_5ls0b8zb53qmw3mlvfz")
end

def test_that_we_can_list_all_receipts
receipts = Omise::Receipt.list

assert receipts
assert_instance_of Omise::List, receipts
assert_instance_of Omise::Receipt, receipts.first
end

def test_that_we_can_retrieve_a_receipt
receipt = Omise::Receipt.retrieve("rcpt_5ls0b8zb53qmw3mlvfz")

assert receipt
assert_instance_of Omise::Receipt, receipt
end

def test_that_we_can_reload_a_receipt
@receipt.attributes.taint
@receipt.reload

refute @receipt.attributes.tainted?
end
end

0 comments on commit 6f943de

Please sign in to comment.