From b57e07c3a415a809a6d2a35e04368aeeb39abbd1 Mon Sep 17 00:00:00 2001 From: AnasNaouchi Date: Tue, 26 Sep 2023 16:11:37 +0700 Subject: [PATCH] Support partial capture --- lib/omise/charge.rb | 2 +- .../chrg_test_5x8glktwl62j63dr3me-get.json | 99 +++++++++++++++++++ test/omise/test_charge.rb | 21 ++++ test/omise/test_http_logger.rb | 2 +- 4 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/api.omise.co/charges/chrg_test_5x8glktwl62j63dr3me-get.json diff --git a/lib/omise/charge.rb b/lib/omise/charge.rb index 608892f..d0475a1 100644 --- a/lib/omise/charge.rb +++ b/lib/omise/charge.rb @@ -37,7 +37,7 @@ def update(attributes = {}) end def capture(options = {}) - assign_attributes nested_resource("capture", options).post + assign_attributes nested_resource("capture", options).post(options) end def reverse(options = {}) diff --git a/test/fixtures/api.omise.co/charges/chrg_test_5x8glktwl62j63dr3me-get.json b/test/fixtures/api.omise.co/charges/chrg_test_5x8glktwl62j63dr3me-get.json new file mode 100644 index 0000000..089de45 --- /dev/null +++ b/test/fixtures/api.omise.co/charges/chrg_test_5x8glktwl62j63dr3me-get.json @@ -0,0 +1,99 @@ +{ + "object": "charge", + "id": "chrg_test_5x8glktwl62j63dr3me", + "location": "/charges/chrg_test_5x8glktwl62j63dr3me", + "amount": 100000, + "authorization_type": "pre_auth", + "authorized_amount": 100000, + "captured_amount": 3000, + "net": 2882, + "fee": 110, + "fee_vat": 8, + "interest": 0, + "interest_vat": 0, + "funding_amount": 3000, + "refunded_amount": 0, + "transaction_fees": { + "fee_flat": "0.0", + "fee_rate": "3.65", + "vat_rate": "7.0" + }, + "platform_fee": { + "fixed": null, + "amount": null, + "percentage": null + }, + "currency": "THB", + "funding_currency": "THB", + "ip": null, + "refunds": { + "object": "list", + "data": [], + "limit": 20, + "offset": 0, + "total": 0, + "location": "/charges/chrg_test_5x8glktwl62j63dr3me/refunds", + "order": "chronological", + "from": "1970-01-01T00:00:00Z", + "to": "2023-09-26T06:15:31Z" + }, + "link": null, + "description": null, + "metadata": {}, + "card": { + "object": "card", + "id": "card_test_5x17kjqylbrla8t3elw", + "livemode": false, + "location": "/customers/cust_test_5x17kjuemequnrjiy3y/cards/card_test_5x17kjqylbrla8t3elw", + "deleted": false, + "street1": null, + "street2": null, + "city": "Bangkok", + "state": null, + "phone_number": null, + "postal_code": "10320", + "country": "us", + "financing": "credit", + "bank": "JPMORGAN CHASE BANK N.A.", + "brand": "Visa", + "fingerprint": "ZmYHTfxzcB4xH5GTzXaPWRRpScr5nGNEDaPJ2XYJQfw=", + "first_digits": null, + "last_digits": "4242", + "name": "JOHN DOE", + "expiration_month": 2, + "expiration_year": 2024, + "security_code_check": true, + "tokenization_method": null, + "created_at": "2023-09-07T17:20:36Z" + }, + "source": null, + "schedule": null, + "customer": "cust_test_5x17kjuemequnrjiy3y", + "dispute": null, + "transaction": "trxn_test_5x8gll1ic0gxf8y4wfd", + "failure_code": null, + "failure_message": null, + "status": "successful", + "authorize_uri": null, + "return_uri": null, + "created_at": "2023-09-26T06:15:17Z", + "paid_at": "2023-09-26T06:15:17Z", + "expires_at": "2023-10-03T06:15:16Z", + "expired_at": null, + "reversed_at": null, + "zero_interest_installments": false, + "branch": null, + "terminal": null, + "device": null, + "authorized": true, + "capturable": false, + "capture": false, + "disputable": true, + "livemode": false, + "refundable": true, + "reversed": false, + "reversible": false, + "voided": false, + "paid": true, + "expired": false +} diff --git a/test/omise/test_charge.rb b/test/omise/test_charge.rb index 4042479..60d5a74 100644 --- a/test/omise/test_charge.rb +++ b/test/omise/test_charge.rb @@ -12,6 +12,15 @@ def test_that_we_can_create_a_charge assert_equal "chrg_test_4yq7duw15p9hdrjp8oq", charge.id end + def test_that_we_can_create_a_partial_charge + @partial_charge_create = Omise::Charge.new(JSON.load('{ "capture": false,"authorization_type":"pre_auth","captured_amount": 0 }')) + + assert_instance_of Omise::Charge, @partial_charge_create + assert_equal false, @partial_charge_create['capture'] + assert_equal "pre_auth", @partial_charge_create.authorization_type + assert_equal 0, @partial_charge_create.captured_amount + end + def test_that_we_can_create_a_charge_even_if_api_key_is_nil without_keys do charge = Omise::Charge.create(key: "skey_test_4yq6tct0lblmed2yp5t") @@ -44,6 +53,18 @@ def test_that_we_can_retrieve_an_expanded_charge assert_instance_of Omise::RefundList, @charge.refunds end + def test_that_we_can_retrieve_a_partial_charge + @partialCharge = Omise::Charge.retrieve("chrg_test_5x8glktwl62j63dr3me") + + assert_instance_of Omise::Charge, @partialCharge + assert_equal "chrg_test_5x8glktwl62j63dr3me", @partialCharge.id + assert_equal "pre_auth", @partialCharge.authorization_type + assert_equal 100000, @partialCharge.authorized_amount + assert_equal 3000, @partialCharge.captured_amount + assert_equal false, @partialCharge['capture'] + + end + def test_that_we_can_list_all_charge charges = Omise::Charge.list diff --git a/test/omise/test_http_logger.rb b/test/omise/test_http_logger.rb index 679d2b4..56b67b4 100644 --- a/test/omise/test_http_logger.rb +++ b/test/omise/test_http_logger.rb @@ -17,7 +17,7 @@ def test_we_can_initialize_a_logger_setting_a_log end def setup - @log_mock = MiniTest::Mock.new + @log_mock = Minitest::Mock.new end def test_we_can_log_an_http_request