Class: Kakeibo

Inherits:
Object
  • Object
show all
Defined in:
lib/kakeibo.rb,
lib/kakeibo/error.rb,
lib/kakeibo/client.rb,
lib/kakeibo/client/iab.rb,
lib/kakeibo/client/iap.rb,
lib/kakeibo/client/base.rb,
lib/kakeibo/client/receipt/iab.rb,
lib/kakeibo/client/receipt/iap.rb

Defined Under Namespace

Classes: Client, Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform, retry_count: 1, logger: nil) ⇒ Kakeibo

Returns a new instance of Kakeibo.



7
8
9
10
11
12
# File 'lib/kakeibo.rb', line 7

def initialize(platform, retry_count: 1, logger: nil)
  @platform     = platform     # :Iap or :Iab
  @retry_count  = retry_count
  @logger       = logger || Logger.new(STDOUT)
  @receipt = nil
end

Instance Attribute Details

#receiptObject (readonly)

Returns the value of attribute receipt.



5
6
7
# File 'lib/kakeibo.rb', line 5

def receipt
  @receipt
end

Instance Method Details

#errorObject



51
52
53
54
# File 'lib/kakeibo.rb', line 51

def error
  return nil if @receipt.nil?
  @receipt.error
end

#fetch(data, option = {}) ⇒ Object

option For IAP :transaction_id -> SKPaymentTransaction#transactionIdentifier OPTIONAL For IAB :signature => included IAB response REQUIRED :base64_encoded_public_key => license key REQUIRED :developer_payload => developer payload OPTIONAL



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/kakeibo.rb', line 21

def fetch(data, option={})
  client   = ::Kakeibo::Client.new @platform
  count    = 0
  response = nil
  begin
    count += 1
    response = client.fetch(data, option)
  rescue => e
    @logger.error("ERROR #{e} #{e.message}")
    if count < @retry_count
      retry
    else
      raise e
    end
  end
  @receipt = client.get_receipt

  # IAP sandboxの場合の処理
  if @receipt.instance_of?(Kakeibo::Client::Receipt::Iap) && @receipt.status == Kakeibo::Client::Receipt::Iap::IS_SANDBOX_STATUS
    response = client.fetch(data, option.merge({environment: :sandbox}))
    @receipt = client.get_receipt
  end
  @receipt
end

#valid?Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/kakeibo.rb', line 46

def valid?
  return false if @receipt.nil?
  @receipt.valid?
end