Skip to content

Commit e2208fa

Browse files
Merge branch 'master' of https://github.com/mekari-engineering/midtrans_api_ruby into KRED-2946
2 parents 4639ba0 + 77fe5e4 commit e2208fa

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
@@ -15,6 +15,7 @@
1515
require 'midtrans_api/api/disbursement/payout'
1616
require 'midtrans_api/api/merchant/create'
1717
require 'midtrans_api/api/merchant/update_notification'
18+
require 'midtrans_api/api/merchant/get'
1819
require 'midtrans_api/api/channel/list'
1920

2021
require 'midtrans_api/middleware/handle_response_exception'
@@ -32,6 +33,7 @@
3233
require 'midtrans_api/model/disbursement/payout'
3334
require 'midtrans_api/model/merchant/create'
3435
require 'midtrans_api/model/merchant/update_notification'
36+
require 'midtrans_api/model/merchant/get'
3537

3638
module MidtransApi
3739
class Client
@@ -110,6 +112,10 @@ def merchant_update_notification
110112
@merchant_update_notification ||= MidtransApi::Api::Merchant::UpdateNotification.new(self)
111113
end
112114

115+
def get_merchant
116+
@merchant_get ||= MidtransApi::Api::Merchant::Get.new(self)
117+
end
118+
113119
def channel
114120
@channel ||= MidtransApi::Api::Channel::List.new(self)
115121
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)