Skip to content
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
19 changes: 19 additions & 0 deletions lib/midtrans_api/api/merchant/get.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module MidtransApi
module Api
module Merchant
class Get < MidtransApi::Api::Base
PATH = 'merchants'

def get(params, partner_id)
response = client.get(PATH, params, {
'X-PARTNER-ID': partner_id
})

MidtransApi::Model::Merchant::Get.new(response)
end
end
end
end
end
6 changes: 6 additions & 0 deletions lib/midtrans_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require 'midtrans_api/api/check/balance'
require 'midtrans_api/api/disbursement/payout'
require 'midtrans_api/api/merchant/create'
require 'midtrans_api/api/merchant/get'
require 'midtrans_api/api/channel/list'

require 'midtrans_api/middleware/handle_response_exception'
Expand All @@ -30,6 +31,7 @@
require 'midtrans_api/model/check/balance'
require 'midtrans_api/model/disbursement/payout'
require 'midtrans_api/model/merchant/create'
require 'midtrans_api/model/merchant/get'

module MidtransApi
class Client
Expand Down Expand Up @@ -104,6 +106,10 @@ def merchant
@merchant ||= MidtransApi::Api::Merchant::Create.new(self)
end

def get_merchant
@merchant_get ||= MidtransApi::Api::Merchant::Get.new(self)
end

def channel
@channel ||= MidtransApi::Api::Channel::List.new(self)
end
Expand Down
25 changes: 25 additions & 0 deletions lib/midtrans_api/model/merchant/get.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require_relative 'item'

module MidtransApi
module Model
module Merchant
class Get < MidtransApi::Model::Base
resource_attributes :merchants

def resolve_params_attr(attr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ini buat apa ya ki?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ini udah standard dari base modelnya bang untuk parsenya

attr.to_s
end

def merchant_list
return [] unless merchants

merchants.map do |merchant_data|
Item.new(merchant_data)
end
end
end
end
end
end
27 changes: 27 additions & 0 deletions lib/midtrans_api/model/merchant/item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module MidtransApi
module Model
module Merchant
class Item < MidtransApi::Model::Base
attr_reader :merchant_id, :merchant_name, :merchant_phone_number, :email

def initialize(merchant_data)
@merchant_id = merchant_data['merchant_id']
@merchant_name = merchant_data['merchant_name']
@merchant_phone_number = merchant_data['merchant_phone_number']
@email = merchant_data['email']
end

def to_h
{
merchant_id: merchant_id,
merchant_name: merchant_name,
merchant_phone_number: merchant_phone_number,
email: email
}
end
end
end
end
end
Loading