TapPay SDK example code for Android Platform.
TapPay Android SDK is used to get token(i.e. prime) on Android platform for charging a credit card.
Obtain your app id and keys here. https://www.tappaysdk.com/en
-
Import tpdirect.aar into your project.
-
Use TPDSetup to initialize the SDK and setup environment.
TPDSetup.initInstance(getApplicationContext(), "APP_ID", "APP_KEY" , TPDServerType.Sandbox);
-
Add TPDForm in your layout.
<tech.cherri.tpdirect.api.TPDForm android:id="@+id/tpdForm" android:layout_width="wrap_content" android:layout_height="wrap_content"> </tech.cherri.tpdirect.api.TPDForm>
-
Setup TPDCard with TPDForm.
TPDCard card = TPDCard.setup(TPDForm tpdForm) .onSuccessCallback(new TPDTokenSuccessCallback(){ @Override public void onSuccess(String prime, TPDCardInfo cardInfo) { //get Prime succeeded. } } ).onFailureCallback(new TPDTokenFailureCallback(){ @Override public void onFailure(int status, String reportMsg) { //get Prime failed. } });
-
Fill credit card information in TPDForm and get Prime from TapPay.
card.getPrime();
-
Import tpdirect.aar into your project.
-
Add dependencies into your app's build.gradle
compile 'com.android.support:appcompat-v7:24.1.1' compile 'com.google.android.gms:play-services-wallet:16.0.0'
-
Add below metadata in AndroidManifest.xml
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true" />
-
Use TPDSetup to initialize the SDK and setup environment.
TPDSetup.initInstance(getApplicationContext(), "APP_ID", "APP_KEY" , TPDServerType.Sandbox);
-
Create :
- TPDMerchant for Google Pay process
TPDMerchant tpdMerchant = new TPDMerchant(); tpdMerchant.setSupportedNetworks(allowedNetworks); tpdMerchant.setSupportedAuthMethods(allowedAuthMethods); tpdMerchant.setMerchantName("Your merchant name");
- TPDConsumer for requiring consumer's payment detail.
TPDConsumer tpdConsumer = new TPDConsumer(); tpdConsumer.setPhoneNumberRequired(true); tpdConsumer.setShippingAddressRequired(true); tpdConsumer.setEmailRequired(true);
-
Setup TPDGooglePay with TPDMerchant and TPDConsumer.
TPDGooglePay tpdGooglePay = new TPDGooglePay(this, tpdMerchant, tpdConsumer);
-
Check Google Pay availability.
tpdGooglePay.isGooglePayAvailable(TPDGooglePayListener var1);
-
Obtain PaymentData.
tpdGooglePay.requestPayment(TransactionInfo.newBuilder() .setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL) .setTotalPrice("1") .setCurrencyCode("TWD") .build(), LOAD_PAYMENT_DATA_REQUEST_CODE);
-
Get Prime from TapPay.
tpdGooglePay.getPrime(paymentData, TPDTokenSuccessCallback, TPDTokenFailureCallback);
-
Import tpdirect.aar into your project.
-
Use TPDSetup to initialize the SDK and setup environment.
TPDSetup.initInstance(getApplicationContext(), "APP_ID", "APP_KEY" , TPDServerType.Sandbox);
-
Add below intent-filter to an Activity for receiving LINE Pay Result in AndroidManifest.xml and set launch mode to "SingleTask"
For example :
<activity android:name=".LinePayActivity" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="tech.cherri" android:scheme="linepayexample" /> </intent-filter> </activity>
-
Check LINE Pay availability.
boolean isLinePayAvailable =TPDLinePay.isLinePayAvailable(Context context);
-
Setup TPDLinePay with uri which is formed with host and scheme(both declared in Step3).
For example:
TPDLinePay tpdLinePay = new TPDLinePay(Context context, "linepayexample://tech.cherri");
-
Open corresponding LinePay payment method by paymentUrl obtained from TapPay pay-by-prime API
tpdLinePay.redirectWithUrl(paymentUrl);
-
Receive LinePayResult in Activity life cycle "onCreate" or "onNewIntent" (depend on the activity had been destroyed or not)
tpdLinePay.parseToLinePayResult(Context context, intent.getData(), TPDLinePayResultListener listener);
-
Obtain TPDLinePayResult in "onParseSuccess" TPDLinePayResult has:
- status (0 = Success , 924 = Canceled by User)
- recTradeId
- bankTransactionId
- orderNumber
-
Import tpdirect.aar and samsungpay-1.x.jar into your project.
-
Add below meta data to your application tag in AndroidManifest.xml
For example :
<application android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme" . . .> <!--Set to 'N' if in release mode.--> <meta-data android:name="debug_mode" android:value="Y" /> <meta-data android:name="spay_sdk_api_level" android:value="1.8" /> <!--Debug Key is valid for 3 months;--> <!--Remove below metadata if in release mode--> <meta-data android:name="spay_debug_api_key" android:value=“{Your debug_api_key obtained from Samsung}” /> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
-
Use TPDSetup to initialize the SDK and setup environment.
TPDSetup.initInstance(getApplicationContext(), "APP_ID", "APP_KEY" , TPDServerType.Sandbox);
-
Create TPDMerchant for Samsung Pay process
TPDMerchant tpdMerchant = new TPDMerchant(); tpdMerchant.setMerchantName(“Your Merchant Name"); tpdMerchant.setSupportedNetworks(allowedNetworks); tpdMerchant.setSamsungMerchantId(“Your SamsungMerchantId obtained from TapPay Portal”)); tpdMerchant.setCurrencyCode("TWD");
-
Setup TPDSamsungPay with TPDMerchant and service Id
TPDSamsungPay tpdSamsungPay = new TPDSamsungPay({Your Activity}, "Your serviceId obtained from Samsung", tpdMerchant);
-
Check Samsung Pay availability.
boolean isSamsungPayAvailable =tpdSamsungPay.isSamsungPayAvailable(TPDSamsungPayStatusListener listener);
-
Get Prime from TapPay.
tpdSamsungPay.getPrime(itemTotalAmount, shippingPrice, tax, totalAmount, TPDTokenSuccessCallback, TPDTokenFailureCallback);