Class: ZakkiStore

Inherits:
Object
  • Object
show all
Defined in:
lib/zakkistore-sdk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url = "https://qris.zakki.store", token = nil, iduser = nil, email = nil, pin = nil, auto_withdraw = false) ⇒ ZakkiStore

Returns a new instance of ZakkiStore.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/zakkistore-sdk.rb', line 8

def initialize(base_url = "https://qris.zakki.store", token = nil, iduser = nil, email = nil, pin = nil, auto_withdraw = false)
  # Smart detection if token is placed in base_url parameter
  if base_url && !base_url.start_with?("http://") && !base_url.start_with?("https://") && token.nil?
    token = base_url
    base_url = "https://qris.zakki.store"
  end

  raise ArgumentError, "token wajib disertakan dalam konfigurasi SDK." if token.nil? || token.empty?
  raise ArgumentError, "base_url wajib disertakan dalam konfigurasi SDK." if base_url.nil? || base_url.empty?

  @base_url = base_url.chomp('/')
  @token = token
  @iduser = iduser
  @email = email
  @pin = pin
  @auto_withdraw = !!auto_withdraw
end

Instance Attribute Details

#auto_withdrawObject

Returns the value of attribute auto_withdraw.



6
7
8
# File 'lib/zakkistore-sdk.rb', line 6

def auto_withdraw
  @auto_withdraw
end

#base_urlObject

Returns the value of attribute base_url.



6
7
8
# File 'lib/zakkistore-sdk.rb', line 6

def base_url
  @base_url
end

#emailObject

Returns the value of attribute email.



6
7
8
# File 'lib/zakkistore-sdk.rb', line 6

def email
  @email
end

#iduserObject

Returns the value of attribute iduser.



6
7
8
# File 'lib/zakkistore-sdk.rb', line 6

def iduser
  @iduser
end

#pinObject

Returns the value of attribute pin.



6
7
8
# File 'lib/zakkistore-sdk.rb', line 6

def pin
  @pin
end

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/zakkistore-sdk.rb', line 6

def token
  @token
end

Instance Method Details

#cancel(id_transaksi = nil, all_pending = false) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/zakkistore-sdk.rb', line 51

def cancel(id_transaksi = nil, all_pending = false)
  if id_transaksi.is_a?(TrueClass) || id_transaksi.is_a?(FalseClass)
    all_pending = id_transaksi
    id_transaksi = nil
  end

  payload = { "token" => @token }
  payload["id_transaksi"] = id_transaksi if id_transaksi
  payload["all"] = true if all_pending
  _request('/cancel', 'POST', payload)
end

#cekgachaObject



227
228
229
# File 'lib/zakkistore-sdk.rb', line 227

def cekgacha
  _request('/cekgacha', 'GET', { "token" => @token })
end

#cekh2h(id_trx) ⇒ Object



90
91
92
# File 'lib/zakkistore-sdk.rb', line 90

def cekh2h(id_trx)
  _request('/cekh2h', 'GET', { "id" => id_trx })
end

#cekminingObject

— 5. REWARD KOMPUTASI & UTILITY —



219
220
221
# File 'lib/zakkistore-sdk.rb', line 219

def cekmining
  _request('/cekmining', 'GET', { "token" => @token })
end

#cektopup(idtopup) ⇒ Object



45
46
47
48
49
# File 'lib/zakkistore-sdk.rb', line 45

def cektopup(idtopup)
  _request('/cektopup', 'GET', {
    "idtopup" => idtopup
  })
end

#checkbankObject

— 3. PERBANKAN & TRANSFER SALDO —



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/zakkistore-sdk.rb', line 102

def checkbank
  payload = { "token" => @token }
  payload["iduser"] = @iduser if @iduser
  payload["email"] = @email if @email

  bank_res = _request('/checkbank', 'GET', payload)

  if @auto_withdraw && bank_res["data"] && bank_res["data"]["bank_detail"]
    bank_detail = bank_res["data"]["bank_detail"]
    balance = (bank_detail["balance"] || 0).to_f

    if balance > 0
      begin
        withdraw_res = tarik(balance.to_i)
        bank_res = _request('/checkbank', 'GET', payload)
        bank_res["auto_withdraw_executed"] = true
        bank_res["auto_withdraw_amount"] = balance.to_i
        bank_res["auto_withdraw_message"] = withdraw_res["message"] || "Auto-withdraw berhasil dijalankan."
      rescue => err
        bank_res["auto_withdraw_executed"] = false
        bank_res["auto_withdraw_error"] = err.message
      end
    end
  end

  bank_res
end

#checkmutasi(mutasi_type = "all") ⇒ Object



172
173
174
175
176
177
178
179
180
# File 'lib/zakkistore-sdk.rb', line 172

def checkmutasi(mutasi_type = "all")
  payload = {
    "token" => @token,
    "type" => mutasi_type
  }
  payload["iduser"] = @iduser if @iduser
  payload["email"] = @email if @email
  _request('/checkmutasi', 'GET', payload)
end

#checkname(number) ⇒ Object



130
131
132
# File 'lib/zakkistore-sdk.rb', line 130

def checkname(number)
  _request('/checkname', 'GET', { "number" => number.to_s.strip })
end

#delwhitelistip(ip) ⇒ Object



238
239
240
241
242
243
# File 'lib/zakkistore-sdk.rb', line 238

def delwhitelistip(ip)
  _request('/delwhitelistip', 'POST', {
    "token" => @token,
    "ip" => ip.to_s.strip
  })
end

#enable_auto_withdraw(status) ⇒ Object



26
27
28
# File 'lib/zakkistore-sdk.rb', line 26

def enable_auto_withdraw(status)
  @auto_withdraw = !!status
end

#enableAutoWithdraw(status) ⇒ Object



30
31
32
# File 'lib/zakkistore-sdk.rb', line 30

def enableAutoWithdraw(status)
  enable_auto_withdraw(status)
end

#h2h(kode, tujuan = nil, ref_id = nil) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/zakkistore-sdk.rb', line 74

def h2h(kode, tujuan = nil, ref_id = nil)
  if kode.is_a?(Hash)
    payload = kode
    kode = payload[:kode] || payload["kode"]
    tujuan = payload[:tujuan] || payload["tujuan"]
    ref_id = payload[:refID] || payload["refID"] || payload[:ref_id] || payload["ref_id"]
  end

  _request('/h2h', 'POST', {
    "token" => @token,
    "kode" => kode,
    "tujuan" => tujuan,
    "refID" => ref_id
  })
end

#leaderboard(limit = 10, period = "all") ⇒ Object



245
246
247
248
249
250
# File 'lib/zakkistore-sdk.rb', line 245

def leaderboard(limit = 10, period = "all")
  _request('/leaderboard', 'GET', {
    "limit" => limit.to_i,
    "period" => period.to_s.strip
  })
end

#listkode(jenis = nil, product_type = nil) ⇒ Object

— 2. TRANSAKSI H2H (HOST-TO-HOST) —



67
68
69
70
71
72
# File 'lib/zakkistore-sdk.rb', line 67

def listkode(jenis = nil, product_type = nil)
  payload = {}
  payload["jenis"] = jenis if jenis
  payload["type"] = product_type if product_type
  _request('/listkode', 'GET', payload)
end

#myh2hObject



94
95
96
# File 'lib/zakkistore-sdk.rb', line 94

def myh2h
  _request('/myh2h', 'GET', { "token" => @token })
end

#myminingObject



223
224
225
# File 'lib/zakkistore-sdk.rb', line 223

def mymining
  _request('/mymining', 'GET', { "token" => @token })
end

#noktelBuy(category) ⇒ Object



190
191
192
193
194
195
# File 'lib/zakkistore-sdk.rb', line 190

def noktelBuy(category)
  _request('/noktel/buy', 'POST', {
    "token" => @token,
    "category" => category.to_s.strip
  })
end

#noktelCancel(invoice_id) ⇒ Object



204
205
206
207
208
209
# File 'lib/zakkistore-sdk.rb', line 204

def noktelCancel(invoice_id)
  _request('/noktel/cancel', 'POST', {
    "token" => @token,
    "invoice_id" => invoice_id.to_s.strip
  })
end

#noktelGetOtp(account_id) ⇒ Object



197
198
199
200
201
202
# File 'lib/zakkistore-sdk.rb', line 197

def noktelGetOtp()
  _request('/noktel/getotp', 'GET', {
    "token" => @token,
    "account_id" => .to_s.strip
  })
end

#noktelHistoryObject



211
212
213
# File 'lib/zakkistore-sdk.rb', line 211

def noktelHistory
  _request('/noktel/history', 'GET', { "token" => @token })
end

#noktelStokObject

— 4. NOKTEL MARKETPLACE (OTP VIRTUAL) —



186
187
188
# File 'lib/zakkistore-sdk.rb', line 186

def noktelStok
  _request('/noktel/stok', 'GET', { "token" => @token })
end

#statusObject



252
253
254
# File 'lib/zakkistore-sdk.rb', line 252

def status
  _request('/status', 'GET')
end

#tabung(jumlah) ⇒ Object

Raises:

  • (RuntimeError)


148
149
150
151
152
153
154
155
156
157
158
# File 'lib/zakkistore-sdk.rb', line 148

def tabung(jumlah)
  raise RuntimeError, "[ZakkiStore SDK Error] PIN transaksi diperlukan untuk melakukan transaksi tabung." unless @pin
  payload = {
    "token" => @token,
    "jumlah" => jumlah.to_i,
    "pin" => @pin
  }
  payload["iduser"] = @iduser if @iduser
  payload["email"] = @email if @email
  _request('/tabung', 'POST', payload)
end

#tarik(jumlah) ⇒ Object

Raises:

  • (RuntimeError)


160
161
162
163
164
165
166
167
168
169
170
# File 'lib/zakkistore-sdk.rb', line 160

def tarik(jumlah)
  raise RuntimeError, "[ZakkiStore SDK Error] PIN transaksi diperlukan untuk melakukan transaksi tarik." unless @pin
  payload = {
    "token" => @token,
    "jumlah" => jumlah.to_i,
    "pin" => @pin
  }
  payload["iduser"] = @iduser if @iduser
  payload["email"] = @email if @email
  _request('/tarik', 'POST', payload)
end

#topup(nominal) ⇒ Object

— 1. PAYMENT GATEWAY (QRIS TOPUP) —



38
39
40
41
42
43
# File 'lib/zakkistore-sdk.rb', line 38

def topup(nominal)
  _request('/topup', 'POST', {
    "token" => @token,
    "nominal" => nominal.to_i
  })
end

#transfer(to, amount = nil) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/zakkistore-sdk.rb', line 134

def transfer(to, amount = nil)
  if to.is_a?(Hash)
    payload = to
    to = payload[:to] || payload["to"]
    amount = payload[:amount] || payload["amount"]
  end

  _request('/transfer', 'POST', {
    "token" => @token,
    "to" => to,
    "amount" => amount.to_i
  })
end

#whitelistip(ip) ⇒ Object



231
232
233
234
235
236
# File 'lib/zakkistore-sdk.rb', line 231

def whitelistip(ip)
  _request('/whitelistip', 'POST', {
    "token" => @token,
    "ip" => ip.to_s.strip
  })
end