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

Support partial capture #55

Merged
merged 4 commits into from
Oct 3, 2023
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
2 changes: 1 addition & 1 deletion lib/omise/charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
25 changes: 25 additions & 0 deletions test/omise/test_charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -107,6 +128,10 @@ def test_that_we_can_send_a_capture_request
assert @charge.capture
end

def test_that_we_can_send_a_capture_request_with_parameters
assert @charge.capture({capture_amount:3000})
end

def test_that_we_can_send_a_reverse_request
assert @charge.reverse
end
Expand Down
2 changes: 1 addition & 1 deletion test/omise/test_http_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down