Skip to content

Commit 77fe5e4

Browse files
authored
Merge pull request #19 from mekari-engineering/KRED-2534
KRED-2534 Add get merchant
2 parents 63212a2 + 6d30376 commit 77fe5e4

5 files changed

Lines changed: 391 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module MidtransApi
4+
module Api
5+
module Merchant
6+
class Get < MidtransApi::Api::Base
7+
PATH = 'merchants'
8+
9+
def get(params, partner_id)
10+
response = client.get(PATH, params, {
11+
'X-PARTNER-ID': partner_id
12+
})
13+
14+
MidtransApi::Model::Merchant::Get.new(response)
15+
end
16+
end
17+
end
18+
end
19+
end

lib/midtrans_api/client.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
require 'midtrans_api/api/check/balance'
1515
require 'midtrans_api/api/disbursement/payout'
1616
require 'midtrans_api/api/merchant/create'
17+
require 'midtrans_api/api/merchant/get'
1718
require 'midtrans_api/api/channel/list'
1819

1920
require 'midtrans_api/middleware/handle_response_exception'
@@ -30,6 +31,7 @@
3031
require 'midtrans_api/model/check/balance'
3132
require 'midtrans_api/model/disbursement/payout'
3233
require 'midtrans_api/model/merchant/create'
34+
require 'midtrans_api/model/merchant/get'
3335

3436
module MidtransApi
3537
class Client
@@ -104,6 +106,10 @@ def merchant
104106
@merchant ||= MidtransApi::Api::Merchant::Create.new(self)
105107
end
106108

109+
def get_merchant
110+
@merchant_get ||= MidtransApi::Api::Merchant::Get.new(self)
111+
end
112+
107113
def channel
108114
@channel ||= MidtransApi::Api::Channel::List.new(self)
109115
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'item'
4+
5+
module MidtransApi
6+
module Model
7+
module Merchant
8+
class Get < MidtransApi::Model::Base
9+
resource_attributes :merchants
10+
11+
def resolve_params_attr(attr)
12+
attr.to_s
13+
end
14+
15+
def merchant_list
16+
return [] unless merchants
17+
18+
merchants.map do |merchant_data|
19+
Item.new(merchant_data)
20+
end
21+
end
22+
end
23+
end
24+
end
25+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
module MidtransApi
4+
module Model
5+
module Merchant
6+
class Item < MidtransApi::Model::Base
7+
attr_reader :merchant_id, :merchant_name, :merchant_phone_number, :email
8+
9+
def initialize(merchant_data)
10+
@merchant_id = merchant_data['merchant_id']
11+
@merchant_name = merchant_data['merchant_name']
12+
@merchant_phone_number = merchant_data['merchant_phone_number']
13+
@email = merchant_data['email']
14+
end
15+
16+
def to_h
17+
{
18+
merchant_id: merchant_id,
19+
merchant_name: merchant_name,
20+
merchant_phone_number: merchant_phone_number,
21+
email: email
22+
}
23+
end
24+
end
25+
end
26+
end
27+
end

0 commit comments

Comments
 (0)