The client integration experience is our priority. This SDK will be a realization from our dedication to give the best service to our client.
sequenceDiagram
Client ->> Server: Inquiry a client number (Inquiry)
Server -->> Client: Response the bills
Client ->> Server: Checkout an order (Checkout)
Server -->> Client: Response the an process order
Server -->> Client: Callback the final status order (Callback)
loop check status every X times until final status
Client ->> Server: Check Status whenever receive an callback (CheckStatus)
Server -->> Client: Response the current order status
end
sequenceDiagram
Client ->> Server: Checkout an order (Checkout)
Server -->> Client: Response the an process order
Server -->> Client: Callback the final status order (Callback)
loop check status every X times until final status
Client ->> Server: Check Status whenever receive an callback (CheckStatus)
Server -->> Client: Response the current order status
end
- Java 8 and above
- Tokopedia Account registered as Distributor SAT, please follow DG B2B - Developer Guideline
- Generate Pair Private Key & Public Key, you can follow API Documentation Section 2.4 Digital Signature
- Share your Public Key to Tokopedia Dev Console under your current apps. We recommend starting from testing apps.
If you're using Maven as the build tools for your project, please add the following dependency to your project's build definition (pom.xml): Maven:
<dependency>
<groupId>io.github.ptsat</groupId>
<artifactId>digitalb2bclient</artifactId>
<version>1.0.0</version>
</dependency>
Gradle: If you're using Gradle as the build tools for your project, please add jcenter repository to your build script then add the following dependency to your project's build definition (build.gradle):
dependencies {
implementation 'io.github.ptsat:digitalb2bclient:1.0.0'
}
Initialize the SDK instance
import io.github.ptsat.digitalb2bclient.DigitalB2BClientImpl;
import io.github.ptsat.digitalb2bclient.Config;
// other code...
Config config = Config.builder()
.setClientID("your client_id")
.setClientSecret("your client secret")
.setPrivateKey("your private key")
.setSATPublicKey("SAT's public key")
.setIsProduction(false) // true for production or real environment.
.build();
DigitalB2BClientImpl SATClient = new DigitalB2BClientImpl(config);
Ignore if the agreement is settlement. Account method used to check current your account balance. This will help you to monitor your account balance. You can utilize this function to prevent it from insufficient balance.
CheckBalanceResponse balance = SATClient.getBalance();
long currentBalance= balance.getData().getAttributes().getsaldo();
Inquiry method mostly used to check a user bill for a product inquiry type
InquiryRequest req = new InquiryRequest(
"telkom-indihome",
"02182221111",
null,
"downline-key");
InquiryResponse inquiryResponse = SATClient.doInquiry(req);
Checkout allows your system to post the order to SAT server. It means the order will be processed, and your balance will be deducted. The process will be asynchronous, so you required to implement Check Status to get the final order status.
CheckOutRequest req = new CheckOutRequest(
"your unique identifier",
"pln-postpaid",
"2121212",
12500,
null,
"downline-key");
CheckOutResponse checkOutResponse = SATClient.doCheckOut(req);
Check Status will return the current order status and the detail order information. Please follow our API Doc to handle each error code.
CheckStatusResponse checkStatusResponse = SATClient.doCheckStatus("your unique identifier");
List product will return all products that are available or specific product when you pass the product code on the parameter.
ProductListResponse productListResponse = SATClient.getProductList();
Client need to expose the Webhook using HTTP Server and implement the Handler using Callback interface. Callback will help you to get the final status order real time based on the event via triggered from webhook.
CallbackRequest req = new CallbackRequest(
"S/WR8OzQbfXluxHwbArPsE23alHRDKAD78aUH1uLP+hIz716QQ0l4y5iya3W/A9/V3IM2GXf5SZlr6vOijGQJgr2jjLeU6B94ZnZVPIKbeehmvR/oog4rnNrFHpgRxA9B/gMeZz6jaJLXNGPR3CsUOg3pxu+fbcTfeuAwBL+8obMhj/xphIZ1j8O79eCxrndkWTRkIeZnUHiSb/MXo118f+U4kjCmOV1azZ0osU+C+HKNACGc6O4jBnGKyTjCKQ4xd2SuEM5A3nfBg+aV7A2prYm14FUJBPsEoeLXWgi4eacWXkXNDZRa+GFjYkB1OZLQNUWL+zLsCecQQXmo4bDZg==",
"{\"data\":{\"type\":\"order\",\"id\":\"test001\",\"attributes\":{\"admin_fee\":0,\"client_name\":\"\",\"client_number\":\"089911311111\",\"error_code\":\"\",\"error_detail\":\"\",\"fields\":null,\"fulfilled_at\":\"2022-07-08T07:37:43Z\",\"fulfillment_result\":[{\"name\":\"Nomor\",\"value\":\"089911311111\"},{\"name\":\"Serial Number\",\"value\":\"TKXL0305956073\"},{\"name\":\"Harga\",\"value\":\"Rp 14.930\"}],\"partner_fee\":0,\"product_code\":\"15k-xl\",\"sales_price\":14930,\"serial_number\":\"TKXL0305956073\",\"status\":\"Success\",\"voucher_code\":\"\"}}}\n");
CallbackResponse callbackResponse = SATClient.getCallback(req);
Order Status "Failed" always exposes error code. You can refer to our API Documentation Section 4.8 Error Response to handle each error code. Below snipped code is the example of how you can handle the error code.
CheckStatusResponse checkStatusResponse = SATClient.doCheckStatus("your unique identifier");
if (checkStatusResponse.getErrors().length > 0){
String errorCode = checkOutResponse.getErrors()[0].getCode();
String errorDetail = checkOutResponse.getErrors()[0].getDetail();
String errorStatus = checkOutResponse.getErrors()[0].getStatus();
}
Please check on the demo folder to see the full implementation for each method.
The MIT License (MIT)
Copyright (c) 2024 Tokopedia
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.