To use Samsung Product API, <script type="text/javascript" src="$WEBAPIS/webapis/webapis.js"></script> Should be loaded in index.html
To use Samsung Product API,
<script type="text/javascript" src="$WEBAPIS/webapis/webapis.js"></script>
Should be loaded in index.html
This module defines the Billing (Samsung Checkout) functionalities provided by the Tizen Samsung TV Product API.
Since : 2.4
Product : TV
Specifies billing server types.
enum TVServerType { "DEV", "PRD" };
The following values are supported
Specifies product types for the purchase history.
enum HistoryType { "ALL", "SUBSCRIPTION", "NON-SUBSCRIPTION" };
Defines a dictionary for product list data returned by the getProductsList API.
dictionary ProductsListData { DOMString CPStatus; DOMString? CPResult; long TotalCount; DOMString CheckValue; ItemDetails? ItemDetails; };
Defines a dictionary for the ProductsListData dictionary 'ItemDetails' parameter.
dictionary ItemDetails { long Seq; DOMString ItemID; DOMString ItemTitle; long ItemType; long? Period; long Price; DOMString CurrencyID; ProductSubscriptionInfo? SubscriptionInfo; };
Defines a dictionary for the ItemDetails dictionary 'SubscriptionInfo' parameter.
dictionary ProductSubscriptionInfo { DOMString PaymentCyclePeriod; long PaymentCycleFrq; long PaymentCycle; };
Defines a dictionary for data returned by the applyInvoice API.
dictionary ApplyInvoiceData { DOMString CPStatus; DOMString? CPResult; DOMString AppliedTime; };
Defines a dictionary for data returned by the verifyInvoice API.
dictionary VerifyInvoiceData { DOMString CPStatus; DOMString? CPResult; DOMString AppID; DOMString InvoiceID; };
Defines a dictionary for data returned by the getUserPurchaseList API.
dictionary UserPurchaseData { DOMString CPStatus; DOMString? CPResult; long TotalCount; DOMString CheckValue; InvoiceDetails? InvoiceDetails; };
dictionary InvoiceDetails { long Seq; DOMString InvoiceID; DOMString ItemID; DOMString ItemTitle; long ItemType; DOMString OrderTime; long? Period; long Price; DOMString OrderCurrencyID; boolean CancelStatus; boolean AppliedStatus; DOMString? AppliedTime; DOMString? LimitEndTime; DOMString? RemainTime; PurchaseSubscriptionInfo? SubscriptionInfo; };
Defines a dictionary for the InvoiceDetails dictionary 'SubscriptionInfo' parameter.
dictionary PurchaseSubscriptionInfo { DOMString SubscriptionId; DOMString SubsStartTime; DOMString SubsEndTime; DOMString SubsStatus; };
Defines a dictionary for subscription cancellation data returned by the cancelSubscription API.
dictionary CancelSubscriptionData { DOMString CPStatus; DOMString? CPResult; DOMString InvoiceID; DOMString? SubsCancelTime; DOMString? SubsStatus; };
Defines a dictionary for data returned by the IsServiceAvailable API.
dictionary ServiceAvailableData{ DOMString status; DOMString result; DOMString serviceYn; };
Defines a WebApi object instance of the Tizen Samsung TV Product API. The webapis.billing object enables access to Billing API functionality.
[NoInterfaceObject]interface BillingManagerObject { readonly attribute BillingManager billing; };
WebApi implements BillingManagerObject;
Privilege level: Public
Privilege: http://developer.samsung.com/privilege/billing
Provides methods for Billing functionalities.
[NoInterfaceObject]interface BillingManager { void buyItem(DOMString appId, TVServerType serverType, DOMString paymentDetails, BillingBuyDataSuccessCallback onsuccess, optional ErrorCallback ? onerror); void getProductsList(DOMString appId, DOMString countryCode, DOMString pageSize, DOMString pageNumber, DOMString checkValue, TVServerType serverType, BillingProductsListCallback onsuccess, optional ErrorCallback ? onerror); void applyInvoice(DOMString appId, DOMString customId, DOMString invoiceId, DOMString countryCode, TVServerType serverType, BillingApplyInvoiceCallback onsuccess, optional ErrorCallback ? onerror); void verifyInvoice(DOMString appId, DOMString customId, DOMString invoiceId, DOMString countryCode, TVServerType serverType, BillingVerifyInvoiceCallback onsuccess, optional ErrorCallback ? onerror); void getUserPurchaseList(DOMString appId, DOMString customId, DOMString countryCode, DOMString pageNumber, DOMString checkValue, TVServerType serverType, BillingGetUserPurchaseListCallback onsuccess, optional ErrorCallback ? onerror); void cancelSubscription(DOMString appId, DOMString invoiceId, DOMString customId, DOMString countryCode, TVServerType serverType, BillingCancelSubscriptionCallback onsuccess, optional ErrorCallback ? onerror); void isServiceAvailable(TVServerType serverType, BillingIsServiceAvailableCallback onsuccess, optional ErrorCallback ? onerror); DOMString getVersion(); };
buyItem
Enables implementing the Samsung Checkout Client module within the application. After authenticating the purchase information through the application, the user can proceed to purchase payment.
In case you want to use this function with Dynamic product item, parameters of "DynmcProductID", "DynmcProductInfo", "DynmcShareCategory", "DynmcTaxCategory" are madatory to use.
void buyItem(DOMString appId, TVServerType serverType, DOMString paymentDetails, BillingBuyDataSuccessCallback onsuccess, optional ErrorCallback ? onerror);
Parameters:
Exceptions:
Code example:
///You should put check TV Servertype and add serverType param as below according to TV status when submit app to apps server/// var strTVServer = webapis.productinfo.getSmartTVServerType(); var serverType; if(strTVServer == "1") { serverType = "DEV"; } else if(strTVServer == "0") { serverType = "PRD"; } ////////////////////////////////// var detailObj = new Object(); detailObj.OrderItemID = productsList.ItemDetails[selectedItem].ItemID; // issued by "getProductsList" detailObj.OrderTitle = productsList.ItemDetails[selectedItem].ItemTitle; // issued by "getProductsList" detailObj.OrderTotal = productsList.ItemDetails[selectedItem].Price.toString(); detailObj.OrderCurrencyID = productsList.ItemDetails[selectedItem].CurrencyID; //detailObj.OrderID = "YOUR_ORDER_ID"; // optional value var uniqueCustomId = webapis.sso.getLoginUid(); //unique identifiable id only for this user detailObj.OrderCustomID = uniqueCustomId; var paymentDetails = JSON.stringify(detailObj); webapis.billing.buyItem(appId, serverType, paymentDetails, function(data) { // For implemention details, see the Samsung Checkout Sample Application console.log("[Billing buyItem]: pay_result [" + data.payResult + "], pay_detail [" + data.payDetail + "]"); }, function(error) { console.log("[Billing buyItem] status:[" + error.code + "] errorName:[" + error.name + "] errorMessage:[" + error.message + "]"); } );
getProductsList
Retrieves the list of products registered on the Billing (DPI) server.
void getProductsList(DOMString appId, DOMString countryCode, DOMString pageSize, DOMString pageNumber, DOMString checkValue, TVServerType serverType, BillingProductsListCallback onsuccess, optional ErrorCallback ? onerror);
Since : 4.0
var tvServer = webapis.productinfo.getSmartTVServerType(); var server = ""; if (tvServer == "1") { server = "DEV"; } else if (tvServer == "0") { server = "PRD"; } var appId = "********"; var countryCode = webapis.productinfo.getSystemConfig(webapis.productinfo.ProductInfoConfigKey.CONFIG_KEY_SERVICE_COUNTRY); var securityKey = "********"; var pageSize = "100"; //sample var pageNumber = "1"; //sample var hash = CryptoJS.HmacSHA256(appId + countryCode, securityKey); var checkValue = CryptoJS.enc.Base64.stringify(hash); var onsuccess = function(data) {}; var onerror = function(error) {}; webapis.billing.getProductsList(appId, countryCode, pageSize, pageNumber, checkValue, server, onsuccess, onerror);
applyInvoice
Checks whether a purchase item has been applied.
void applyInvoice(DOMString appId, DOMString customId, DOMString invoiceId, DOMString countryCode, TVServerType serverType, BillingApplyInvoiceCallback onsuccess, optional ErrorCallback ? onerror);
var tvServer = webapis.productinfo.getSmartTVServerType(); var server = ""; if (tvServer == "1") { server = "DEV"; } else if (tvServer == "0") { server = "PRD"; } var appId = "**********"; var uniqueCustomId = webapis.sso.getLoginUid(); //unique identifiable id only for this user var orderCustomID = uniqueCustomId; var invoiceID = "*********"; // Issued by getUserPurchaseList var countryCode = webapis.productinfo.getSystemConfig(webapis.productinfo.ProductInfoConfigKey.CONFIG_KEY_SERVICE_COUNTRY); var onsuccess = function(data) {}; var onerror = function(error) {}; webapis.billing.applyInvoice(appId, orderCustomID, invoiceID, countryCode, server, onsuccess, onerror);
verifyInvoice
Checks whether a purchase, corresponding to a specific "InvoiceID", was successful.
void verifyInvoice(DOMString appId, DOMString customId, DOMString invoiceId, DOMString countryCode, TVServerType serverType, BillingVerifyInvoiceCallback onsuccess, optional ErrorCallback ? onerror);
var tvServer = webapis.productinfo.getSmartTVServerType(); var server = ""; if (tvServer == "1") { server = "DEV"; } else if (tvServer == "0") { server = "PRD"; } var appId = "**********"; var uniqueCustomId = webapis.sso.getLoginUid(); //unique identifiable id only for this user var orderCustomID = uniqueCustomId; var invoiceID = "*********"; // Issued by getUserPurchaseList var countryCode = webapis.productinfo.getSystemConfig(webapis.productinfo.ProductInfoConfigKey.CONFIG_KEY_SERVICE_COUNTRY); var onsuccess = function(data) {}; var onerror = function(error) {}; webapis.billing.verifyInvoice(appId, orderCustomID, invoiceID, countryCode, server, onsuccess, onerror);
getUserPurchaseList
Retrieves the user's purchase list.
void getUserPurchaseList(DOMString appId, DOMString customId, DOMString countryCode, DOMString pageNumber, DOMString checkValue, TVServerType serverType, BillingGetUserPurchaseListCallback onsuccess, optional ErrorCallback ? onerror);
var tvServer = webapis.productinfo.getSmartTVServerType(); var server = ""; if (tvServer == "1") { server = "DEV"; } else if (tvServer == "0") { server = "PRD"; } var appId = "********"; var uniqueCustomId = webapis.sso.getLoginUid(); //unique identifiable id only for this user var orderCustomID = uniqueCustomId; var countryCode = webapis.productinfo.getSystemConfig(webapis.productinfo.ProductInfoConfigKey.CONFIG_KEY_SERVICE_COUNTRY); var securityKey = "********"; var itemType = "2"; var pageNumber = "1"; var hash = CryptoJS.HmacSHA256(appId + orderCustomID + countryCode + itemType + pageNumber, securityKey); var strCheckValue = CryptoJS.enc.Base64.stringify(hash); var onsuccess = function(res){}; var onerror = function(error){}; webapis.billing.getUserPurchaseList(appId, orderCustomID, countryCode, pageNumber, strCheckValue, server, onsuccess, onerror);
cancelSubscription
Cancels a subscription product.
void cancelSubscription(DOMString appId, DOMString invoiceId, DOMString customId, DOMString countryCode, TVServerType serverType, BillingCancelSubscriptionCallback onsuccess, optional ErrorCallback ? onerror);
var tvServer = webapis.productinfo.getSmartTVServerType(); var server = ""; if (tvServer == "1") { server = "DEV"; } else if (tvServer == "0") { server = "PRD"; } var appId = "3201503001547"; var uniqueCustomId = webapis.sso.getLoginUid(); //unique identifiable id only for this user var orderCustomID = uniqueCustomId; var invoiceID = "*********"; // Issued by getUserPurchaseList var countryCode = webapis.productinfo.getSystemConfig(webapis.productinfo.ProductInfoConfigKey.CONFIG_KEY_SERVICE_COUNTRY); var onsuccess = function(data) {}; var onerror = function(error) {}; webapis.billing.cancelSubscription(appId, invoiceID, orderCustomID , countryCode , server, onsuccess, onerror);
isServiceAvailable
Checks whether the Billing server is available.
void isServiceAvailable(TVServerType serverType, BillingIsServiceAvailableCallback onsuccess, optional ErrorCallback ? onerror);
var onsuccess = function(data) {}; var onerror = function(error) {}; webapis.billing.isServiceAvailable("DEV", onsuccess, onerror)
getVersion
Retrieves the Billing API version.
DOMString getVersion();
Privilege level:
Public Privilege: http://developer.samsung.com/privilege/billing
Return value: Billing API version
var version = webapis.billing.getVersion();
Defines the payment success callback.
[Callback = FunctionOnly, NoInterfaceObject]interface BillingBuyDataSuccessCallback { void onsuccess(BillingBuyData data); };
onsuccess
Callback method returning the payment status.
void onsuccess(BillingBuyData data);
void onsuccess(data) { if(data.payResult == SUCCESS) { // Implement success logic } else { // Implement cancel or fail logic } }
Defines the payment result and information.
[NoInterfaceObject] interface BillingBuyData{ readonly attribute DOMString payResult; readonly attribute DOMString payDetail; };
Defines the product list success callback.
[Callback = FunctionOnly, NoInterfaceObject]interface BillingProductsListCallback { void onsuccess(ProductsListData data); };
Callback method returning the product list request status.
void onsuccess(ProductsListData data);
void onsuccess(data) { if(data.CPStatus == "10000") { // Implement success logic } else { // Implement cancel or fail logic } }
Defines the apply invoice success callback.
[Callback = FunctionOnly, NoInterfaceObject]interface BillingApplyInvoiceCallback { void onsuccess(ApplyInvoiceData data); };
Callback method returning the apply invoice request status.
Defines the payment verification success callback.
[Callback = FunctionOnly, NoInterfaceObject]interface BillingVerifyInvoiceCallback { void onsuccess(VerifyInvoiceData data); };
Callback method returning the payment verification request status.
void onsuccess(VerifyInvoiceData data);
Defines the purchase history success callback.
[Callback = FunctionOnly, NoInterfaceObject]interface BillingGetUserPurchaseListCallback { void onsuccess(UserPurchaseData data); };
Callback method returning the purchase history request status.
void onsuccess(UserPurchaseData data);
Defines the subscription cancel success callback.
[Callback = FunctionOnly, NoInterfaceObject]interface BillingCancelSubscriptionCallback { void onsuccess(CancelSubscriptionData data); };
Callback method returning the subscription cancel request status.
Defines the service availability check success callback.
[Callback = FunctionOnly, NoInterfaceObject]interface BillingIsServiceAvailableCallback { void onsuccess(ServiceAvailableData data); };
Callback method returning the service availability check status.
void onsuccess(ServiceAvailableData data);
void onsuccess(data) { if(data.serviceYn == "Y") { // Implement success logic } else { // Implement cancel or fail logic } }
module Billing { enum TVServerType { "DEV", "PRD" }; enum HistoryType { "ALL", "SUBSCRIPTION", "NON-SUBSCRIPTION" }; dictionary ProductsListData { DOMString CPStatus; DOMString? CPResult; long TotalCount; DOMString CheckValue; ItemDetails? ItemDetails; }; dictionary ItemDetails { long Seq; DOMString ItemID; DOMString ItemTitle; long ItemType; long? Period; long Price; DOMString CurrencyID; ProductSubscriptionInfo? SubscriptionInfo; }; dictionary ProductSubscriptionInfo { DOMString PaymentCyclePeriod; long PaymentCycleFrq; long PaymentCycle; }; dictionary ApplyInvoiceData { DOMString CPStatus; DOMString? CPResult; DOMString AppliedTime; }; dictionary VerifyInvoiceData { DOMString CPStatus; DOMString? CPResult; DOMString AppID; DOMString InvoiceID; }; dictionary UserPurchaseData { DOMString CPStatus; DOMString? CPResult; long TotalCount; DOMString CheckValue; InvoiceDetails? InvoiceDetails; }; dictionary InvoiceDetails { long Seq; DOMString InvoiceID; DOMString ItemID; DOMString ItemTitle; long ItemType; DOMString OrderTime; long? Period; long Price; DOMString OrderCurrencyID; boolean CancelStatus; boolean AppliedStatus; DOMString? AppliedTime; DOMString? LimitEndTime; DOMString? RemainTime; PurchaseSubscriptionInfo? SubscriptionInfo; }; dictionary PurchaseSubscriptionInfo { DOMString SubscriptionId; DOMString SubsStartTime; DOMString SubsEndTime; DOMString SubsStatus; }; dictionary CancelSubscriptionData { DOMString CPStatus; DOMString? CPResult; DOMString InvoiceID; DOMString? SubsCancelTime; DOMString? SubsStatus; }; dictionary ServiceAvailableData{ DOMString status; DOMString result; DOMString serviceYn; }; [NoInterfaceObject]interface BillingManagerObject { readonly attribute BillingManager billing; }; WebApi implements BillingManagerObject; [NoInterfaceObject]interface BillingManager { void buyItem(DOMString appId, TVServerType serverType, DOMString paymentDetails, BillingBuyDataSuccessCallback onsuccess, optional ErrorCallback ? onerror); void getProductsList(DOMString appId, DOMString countryCode, DOMString pageSize, DOMString pageNumber, DOMString checkValue, TVServerType serverType, BillingProductsListCallback onsuccess, optional ErrorCallback ? onerror); void applyInvoice(DOMString appId, DOMString customId, DOMString invoiceId, DOMString countryCode, TVServerType serverType, BillingApplyInvoiceCallback onsuccess, optional ErrorCallback ? onerror); void verifyInvoice(DOMString appId, DOMString customId, DOMString invoiceId, DOMString countryCode, TVServerType serverType, BillingVerifyInvoiceCallback onsuccess, optional ErrorCallback ? onerror); void getUserPurchaseList(DOMString appId, DOMString customId, DOMString countryCode, DOMString pageNumber, DOMString checkValue, TVServerType serverType, BillingGetUserPurchaseListCallback onsuccess, optional ErrorCallback ? onerror); void cancelSubscription(DOMString appId, DOMString invoiceId, DOMString customId, DOMString countryCode, TVServerType serverType, BillingCancelSubscriptionCallback onsuccess, optional ErrorCallback ? onerror); void isServiceAvailable(TVServerType serverType, BillingIsServiceAvailableCallback onsuccess, optional ErrorCallback ? onerror); DOMString getVersion(); }; [Callback = FunctionOnly, NoInterfaceObject]interface BillingBuyDataSuccessCallback { void onsuccess(BillingBuyData data); }; [NoInterfaceObject] interface BillingBuyData{ readonly attribute DOMString payResult; readonly attribute DOMString payDetail; }; [Callback = FunctionOnly, NoInterfaceObject]interface BillingProductsListCallback { void onsuccess(ProductsListData data); }; [Callback = FunctionOnly, NoInterfaceObject]interface BillingApplyInvoiceCallback { void onsuccess(ApplyInvoiceData data); }; [Callback = FunctionOnly, NoInterfaceObject]interface BillingVerifyInvoiceCallback { void onsuccess(VerifyInvoiceData data); }; [Callback = FunctionOnly, NoInterfaceObject]interface BillingGetUserPurchaseListCallback { void onsuccess(UserPurchaseData data); }; [Callback = FunctionOnly, NoInterfaceObject]interface BillingCancelSubscriptionCallback { void onsuccess(CancelSubscriptionData data); }; [Callback = FunctionOnly, NoInterfaceObject]interface BillingIsServiceAvailableCallback { void onsuccess(ServiceAvailableData data); }; };