Class: Cin7API::PaymentResource
- Defined in:
- lib/cin7_api/resources/payment_resource.rb
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#create(attributes_array) ⇒ Object
attributes_array = [ { orderType: “CreditNote”, orderRef: “CRN-2223”, orderId: 2223, method: “Not Paid”, amount: 10, paymentDate: “2022-09-10T09:00:00Z”, } ] @client.payment.create(attributes_array).
-
#find(id) ⇒ Object
@client.payment.find(698).
-
#find_by(**params) ⇒ Object
@client.payment.find_by(order_id: 2223, order_ref: “CRN-2223”).
-
#update(attributes_array) ⇒ Object
attributes_array = [ { id: 712, orderId: 2223, method: “manual”, amount: 0, } ] @client.payment.update(attributes_array).
-
#where(**params) ⇒ Object
@client.payment.where(order_id: 2223, order_ref: “CRN-2223”).
Methods inherited from Resource
#get_request, #handle_response, #initialize, #post_request, #put_request
Constructor Details
This class inherits a constructor from Cin7API::Resource
Instance Method Details
#create(attributes_array) ⇒ Object
attributes_array = [
{
orderType: "CreditNote",
orderRef: "CRN-2223",
orderId: 2223,
method: "Not Paid",
amount: 10,
paymentDate: "2022-09-10T09:00:00Z",
}
] @client.payment.create(attributes_array)
36 37 38 39 |
# File 'lib/cin7_api/resources/payment_resource.rb', line 36 def create(attributes_array) responses = post_request("Payments", body: attributes_array).body responses.map { |attributes| Response.new(attributes) } end |
#find(id) ⇒ Object
@client.payment.find(698)
21 22 23 |
# File 'lib/cin7_api/resources/payment_resource.rb', line 21 def find(id) Payment.new(get_request("Payments/#{id}").body) end |
#find_by(**params) ⇒ Object
@client.payment.find_by(order_id: 2223, order_ref: “CRN-2223”)
16 17 18 |
# File 'lib/cin7_api/resources/payment_resource.rb', line 16 def find_by(**params) where(**params).first end |
#update(attributes_array) ⇒ Object
attributes_array = [
{
id: 712,
orderId: 2223,
method: "manual",
amount: 0,
}
] @client.payment.update(attributes_array)
50 51 52 53 |
# File 'lib/cin7_api/resources/payment_resource.rb', line 50 def update(attributes_array) responses = put_request("Payments", body: attributes_array).body responses.map { |attributes| Response.new(attributes) } end |
#where(**params) ⇒ Object
@client.payment.where(order_id: 2223, order_ref: “CRN-2223”)
6 7 8 9 10 11 12 13 |
# File 'lib/cin7_api/resources/payment_resource.rb', line 6 def where(**params) response_body = get_request("Payments", params: params).body payments = response_body.map { |attributes| Payment.new(attributes) } # Doing a filter here because Cin7 is doing a binary OR check for the filter params payments.filter do |payment| params.reduce(true) { |acc, (key, value)| acc && payment[key] == value } end end |