More Related Content
Similar to Chromeウェブストア - Html5とか勉強会42 (7)
More from Yoichiro Tanaka (12)
Chromeウェブストア - Html5とか勉強会42
- 4. The Chrome Web Store lets you
publish apps and games – either free
or paid – where Google Chrome users
can easily find them.
- 6. The Chrome Web Store lets you
publish apps and games – either free
or paid – where Google Chrome users
can easily find them.
- 9. The Chrome Web Store lets you
publish apps and games – either free
or paid – where Google Chrome users
can easily find them.
- 29. # Licensing APIのエンドポイント
ENDPOINT = 'https://www.googleapis.com/chromewebstore/v1/licenses'
# アプリID
APP_ID = '...'
# OAuthトークン
OAUTH_TOKEN = '...'
# OAuthトークンシークレット
OAUTH_TOKEN_SECRET = '...'
# ユーザーのOpenID URL文字列
user_id = ...
# OAuthクライアントの生成
client = Signet::OAuth1::Client.new(
:client_credential_key => 'anonymous',
:client_credential_secret => 'anonymous',
:token_credential_key => OAUTH_TOKEN,
:token_credential_secret => OAUTH_TOKEN_SECRET
)
# リクエストの送信
response = client.fetch_protected_resource(
:uri => "ENDPOINT/#{app_id}/#{CGI::escape(user_id)}"
)
# 結果の取得
result = JSON.parse(response.body)
- 31. result値 accessLevel値 状況
YES FULL ユーザーはアプリに課金している。
YES FREE_TRIAL ユーザーはアプリに課金してなく、
無料試用版を使うべき。
NO NONE ユーザーはアプリに課金してなく、
アプリにアクセスしていない。
- 34. {
"iss": "購入者ID",
"aud": "Google",
"typ": "google/payments/inapp/item/v1",
"exp": "1358678162",
"iat": "1358674585",
"request": {
"name": "Red potion",
"description": "It increases the hit point.",
"price": "2.50",
"currencyCode": "USD",
"sellerData": "user_id:123,transaction_id:98765"
}
}
- 35. SELLER_IDENTIFIER = '販売者 ID'
SELLER_SECRET = '販売者の秘密鍵'
token = JWT.encode(
{
'iss' => SELLER_IDENTIFIER,
'aud' => 'Google',
'typ' => 'google/payments/inapp/item/v1',
'exp' => (Time.now + 3600).to_i,
'iat' => Time.now.to_i,
'request' => {
'name' => 'Red potion',
'description' => 'It increases the hit point.',
'price' => '2.50',
'currencyCode' => 'USD',
'sellerData' => 'user_id =>123,transaction_id =>98765'
}
}, SELLER_SECRET)
- 39. var generatedJwt = ...;
document.getElementById("buy").onclick = function(evt) {
purchase();
};
function purchase() {
...
goog.payments.inapp.buy({
jwt: generatedJwt,
success: function(result) { ... },
failure: function(result) { ... }
});
}
- 42. {
"iss": "Google",
"aud": "購入者ID",
"typ": "google/payments/inapp/item/v1/postback/buy",
"exp": "1358678162",
"iat": "1358674585",
"request": {
"name": "Red potion",
"description": "It increases the hit point.",
"price": "2.50",
"currencyCode": "USD",
"sellerData": "user_id:12345,transaction_id:98765"
},
"response": {
"orderId": "3485709183457474939449"
}
}
- 43. SELLER_SECRET = '販売者の秘密鍵'
encoded_jwt = params['jwt']
item_token = JWT.decode(encoded_jwt, SELLER_SECRET)
order_id = item_token['response']['orderId']
# デコードされた内容に基づいて、注文内容を確認し、
# 必要があればデータベースに注文完了を書き込む
render text: order_id
- 46. var generatedJwt = ...;
document.getElementById("buy").onclick = function(evt) {
purchase();
};
function purchase() {
...
goog.payments.inapp.buy({
jwt: generatedJwt,
success: function(result) { ... },
failure: function(result) { ... }
});
}
- 53. • 田中 洋一郎
– Google Developers Expert (Chrome)
– LINE株式会社 開発1センター所属