Class: Roku::Iap::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/roku/iap/client.rb

Constant Summary collapse

PRODUCTION_HOST =
"https://apipub.roku.com"

Instance Method Summary collapse

Constructor Details

#initialize(dev_token) ⇒ Client

Returns a new instance of Client.



8
9
10
11
# File 'lib/roku/iap/client.rb', line 8

def initialize(dev_token)
  @dev_token = dev_token 
  @host = PRODUCTION_HOST
end

Instance Method Details

#cancel_subscription(transaction_id, cancellation_date, partner_ref_id = "") ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/roku/iap/client.rb', line 23

def cancel_subscription(transaction_id, cancellation_date, partner_ref_id="")
  path = "/listen/transaction-service.svc/cancel-subscription"
  request_body_json = { 
    :partnerAPIKey => @dev_token,
    :transactionId => transaction_id,
    :cancellationDate => cancellation_date,
    :partnerReferenceId => partner_ref_id
  }.to_json
  post_data(path, request_body_json)
end

#refund_subscription(transaction_id, amount, partner_ref_id = "", comments = "") ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/roku/iap/client.rb', line 34

def refund_subscription(transaction_id, amount, partner_ref_id="", comments="")

  unless amount.match(/\d+/)
    # The Roku API returns 400 if amount is not parsable
    raise Roku::Iap::Exceptions::TypeError, "Ensure amount is integer or float!"
  end

  path = "/listen/transaction-service.svc/refund-subscription"
  request_body_json = {
    :partnerAPIKey => @dev_token,
    :transactionId => transaction_id,
    :amount => amount, 
    :partnerReferenceId => partner_ref_id,
    :comments => comments
  }.to_json
  post_data(path, request_body_json.to_s)
end

#validate_refund(refund_id) ⇒ Object



18
19
20
21
# File 'lib/roku/iap/client.rb', line 18

def validate_refund(refund_id)
  path = "/listen/transaction-service.svc/validate-refund/#{@dev_token}/#{refund_id}"
  get_data(path)
end

#validate_transaction(transaction_id) ⇒ Object



13
14
15
16
# File 'lib/roku/iap/client.rb', line 13

def validate_transaction(transaction_id)
  path = "/listen/transaction-service.svc/validate-transaction/#{@dev_token}/#{transaction_id}"
  get_data(path)
end