### Initialize Redeban Payment SDK Source: https://github.com/globalpayredeban/globalpayredeban-android/blob/master/README.md Example of initializing the Redeban Payment SDK within an Android Activity. This is crucial for setting up the environment (test or production) and providing necessary credentials. ```java import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import com.redeban.payment.Payment; import com.redeban.payment.example.utils.Constants; public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /** * Init library * * @param test_mode false to use production environment * @param redeban_client_app_code provided by Redeban. * @param redeban_client_app_key provided by Redeban. */ Payment.setEnvironment(Constants.REDEBAN_IS_TEST_MODE, Constants.REDEBAN_CLIENT_APP_CODE, Constants.REDEBAN_CLIENT_APP_KEY); // In case you have your own Fraud Risk Merchant Id //Payment.setRiskMerchantId(1000); // Note: for most of the devs, that's not necessary. } } ``` -------------------------------- ### Configure and Use CardMultilineWidget in Android Activity Source: https://context7.com/globalpayredeban/globalpayredeban-android/llms.txt Provides a Java example for integrating the CardMultilineWidget within an Android Activity. It covers finding the widget by ID, programmatically setting its properties, and implementing a listener for card input events. It also shows how to retrieve validated card data. ```java import com.redeban.payment.model.Card; import com.redeban.payment.view.CardMultilineWidget; import com.redeban.payment.view.CardInputListener; public class AddCardActivity extends AppCompatActivity { private CardMultilineWidget cardWidget; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_card); cardWidget = findViewById(R.id.card_multiline_widget); // Optional: Customize widget behavior programmatically cardWidget.setShouldShowCardHolderName(true); cardWidget.setShouldShowPostalCode(false); cardWidget.setShouldShowScanCard(true); cardWidget.setShouldShowRedebanLogo(true); // Optional: Listen for card input events cardWidget.setCardInputListener(new CardInputListener() { @Override public void onFocusChange(String focusField) { Log.d("CardInput", "Focus changed to: " + focusField); } @Override public void onCardComplete() { Log.d("CardInput", "Card number complete"); } @Override public void onExpirationComplete() { Log.d("CardInput", "Expiration date complete"); } @Override public void onCvcComplete() { Log.d("CardInput", "CVC complete"); } @Override public void onPostalCodeComplete() { Log.d("CardInput", "Postal code complete"); } }); } private void onSubmitClicked() { // Get validated card from widget // Returns null if any field is invalid (error states shown automatically) Card card = cardWidget.getCard(); if (card != null) { // Card is valid, proceed with tokenization String cardNumber = card.getNumber(); // "4242424242424242" Integer expMonth = card.getExpiryMonth(); // 12 Integer expYear = card.getExpiryYear(); // 2025 String holderName = card.getHolderName(); // "John Doe" String cardType = card.getType(); // "vi" (Visa) // Use Payment.addCard() to tokenize tokenizeCard(card); } } } ``` -------------------------------- ### Add CardMultilineWidget to Layout Source: https://github.com/globalpayredeban/globalpayredeban-android/blob/master/README.md Example of adding the CardMultilineWidget to an Android XML layout. This widget provides a UI for collecting credit card details. ```xml ``` -------------------------------- ### Get Card Object from Widget Source: https://github.com/globalpayredeban/globalpayredeban-android/blob/master/README.md Java code snippet demonstrating how to retrieve a Card object from the CardMultilineWidget. It includes error handling for cases where the card data is invalid. ```java Card cardToSave = cardWidget.getCard(); if (cardToSave == null) { Alert.show(mContext, "Error", "Invalid Card Data"); return; } ``` -------------------------------- ### Get Session ID (Java) Source: https://github.com/globalpayredeban/globalpayredeban-android/blob/master/README.md Retrieves a session ID used by Redeban for fraud prevention. This ID can be collected to gather user device information and passed to your server for charging the user. ```java String session_id = Payment.getSessionId(mContext); ``` -------------------------------- ### Create Card Objects using Card Class Constructors and Builder Source: https://context7.com/globalpayredeban/globalpayredeban-android/llms.txt Demonstrates how to create `Card` objects using different constructors provided by the `Card` class, including options for basic information, cardholder name, and full billing address. It also shows how to utilize the `Card.Builder` pattern for a more fluent and flexible card object creation process. This approach allows for varied instantiation based on available data. ```java import com.redeban.payment.model.Card; public class CardValidationExample { // Simple constructor with basic card info public Card createCardSimple() { return new Card( "4242424242424242", // Card number 12, // Expiry month (1-12) 2025, // Expiry year "123" // CVC ); } // Constructor with cardholder name public Card createCardWithName() { return new Card( "4242424242424242", 12, 2025, "123", "John Doe" // Cardholder name ); } // Full constructor with billing address public Card createCardFull() { return new Card( "4242424242424242", // number 12, // expMonth 2025, // expYear "123", // cvc "John Doe", // name "123 Main St", // addressLine1 "Apt 4B", // addressLine2 "New York", // addressCity "NY", // addressState "10001", // addressZip "US", // addressCountry "USD" // currency ); } // Using the Builder pattern public Card createCardWithBuilder() { return new Card.Builder( "5555555555554444", // Mastercard number 11, // Expiry month 2026, // Expiry year "456" // CVC ) .name("Jane Smith") .addressLine1("456 Oak Avenue") .addressCity("Los Angeles") .addressState("CA") .addressZip("90001") .addressCountry("US") .currency("USD") .build(); } } ``` -------------------------------- ### Add Redeban Android SDK Dependency Source: https://github.com/globalpayredeban/globalpayredeban-android/blob/master/README.md Instructions for adding the Redeban Payment Android SDK to your project's build.gradle file using JitPack. This involves configuring repositories and adding the implementation dependency. ```gradle allprojects { repositories { ... maven { url 'https://jitpack.io' } } } implementation 'com.github.globalpayredeban:globalpayredeban-android:1.2.9' ``` -------------------------------- ### Enable XML Namespace for Custom Attributes Source: https://github.com/globalpayredeban/globalpayredeban-android/blob/master/README.md Shows how to enable the app XML namespace in your layout file, which is necessary to use custom attributes like those for the CardMultilineWidget. ```xml xmlns:app="http://schemas.android.com/apk/res-auto" ``` -------------------------------- ### Add Card and Handle Response (Java) Source: https://github.com/globalpayredeban/globalpayredeban-android/blob/master/README.md Converts sensitive card data into a single-use token for secure server-side charging. It handles success and error callbacks, providing card status, token, and transaction reference on success, or error details on failure. The callback is invoked on the UI thread. ```java Payment.addCard(mContext, uid, email, cardToSave, new TokenCallback() { public void onSuccess(Card card) { if(card != null){ if(card.getStatus().equals("valid")){ Alert.show(mContext, "Card Successfully Added", "status: " + card.getStatus() + "\n" + "Card Token: " + card.getToken() + "\n" + "transaction_reference: " + card.getTransactionReference()); } else if (card.getStatus().equals("review")) { Alert.show(mContext, "Card Under Review", "status: " + card.getStatus() + "\n" + "Card Token: " + card.getToken() + "\n" + "transaction_reference: " + card.getTransactionReference()); } else { Alert.show(mContext, "Error", "status: " + card.getStatus() + "\n" + "message: " + card.getMessage()); } } //TODO: Create charge or Save Token to your backend } public void onError(RedebanError error) { Alert.show(mContext, "Error", "Type: " + error.getType() + "\n" + "Help: " + error.getHelp() + "\n" + "Description: " + error.getDescription()); //TODO: Handle error } }); ``` ```java Payment.addCard( mContext, uid, email, cardToSave, new TokenCallback() { public void onSuccess(Card card) { // Send token to your own web service MyServer.chargeToken(card.getToken()); } public void onError(RedebanError error) { Toast.makeText(getContext(), error.getDescription(), Toast.LENGTH_LONG).show(); } } ); ``` -------------------------------- ### ProGuard Configuration for Redeban SDK (Proguard) Source: https://context7.com/globalpayredeban/globalpayredeban-android/llms.txt Configure ProGuard rules to prevent obfuscation of Redeban SDK classes during code optimization. This ensures the SDK's functionality remains intact after the build process. ```proguard # In your proguard-rules.pro file -keep class com.redeban.payment.** { *; } ``` -------------------------------- ### Configure ProGuard for Redeban SDK Source: https://github.com/globalpayredeban/globalpayredeban-android/blob/master/README.md This snippet shows how to configure ProGuard to exclude Redeban bindings when optimizing your Android app. This prevents issues with obfuscation and ensures the SDK functions correctly. ```proguard -keep class com.redeban.payment.** { *; } ``` -------------------------------- ### Access Card Properties After Tokenization (Java) Source: https://context7.com/globalpayredeban/globalpayredeban-android/llms.txt Retrieve token, transaction reference, card status, masked details, and other relevant information after successful card tokenization. This data is crucial for server-side processing and displaying information to the user. ```java import com.redeban.payment.model.Card; import com.redeban.payment.rest.TokenCallback; import com.redeban.payment.rest.model.RedebanError; public class CardResponseExample { private void handleTokenResponse(Card card) { // After successful tokenization, access card properties // Token for charging (send to your server) String token = card.getToken(); // Example: "tok_abc123xyz789" // Transaction reference for tracking String transactionRef = card.getTransactionReference(); // Example: "TR-2024-001234" // Card status String status = card.getStatus(); // "valid" - Card accepted // "review" - Card under fraud review // "rejected" - Card declined // Masked card details (safe to display/store) String last4 = card.getLast4(); // Example: "4242" String cardType = card.getType(); // Example: "vi" (Visa) String bin = card.getBin(); // First 6 digits (BIN/IIN) // Error message if rejected String message = card.getMessage(); // Example: "Insufficient funds" // Expiry information Integer expMonth = card.getExpiryMonth(); // 12 Integer expYear = card.getExpiryYear(); // 2025 // Cardholder name String holderName = card.getHolderName(); // Example: "John Doe" // Billing address (if provided) String addressLine1 = card.getAddressLine1(); String addressCity = card.getAddressCity(); String addressState = card.getAddressState(); String addressZip = card.getAddressZip(); String addressCountry = card.getAddressCountry(); } } ``` -------------------------------- ### Validate Card Data using Card Class and CardUtils Source: https://context7.com/globalpayredeban/globalpayredeban-android/llms.txt Illustrates how to perform card data validation using the `Card` class's built-in methods for individual fields (number, expiry date, CVC, month) and the comprehensive `validateCard()` method. It also shows how to detect card brands and check card number validity using the `CardUtils` utility class. This ensures data integrity before processing. ```java import com.redeban.payment.model.Card; import com.redeban.payment.util.CardUtils; public class ValidationExample { public void validateCard() { Card card = new Card("4242424242424242", 12, 2025, "123"); // Validate individual fields boolean isNumberValid = card.validateNumber(); // Uses Luhn algorithm to verify card number format // Returns: true boolean isExpiryValid = card.validateExpiryDate(); // Checks if expiry date is in the future // Returns: true (if current date is before 12/2025) boolean isCvcValid = card.validateCVC(); // Validates CVC length (3 digits, or 4 for Amex) // Returns: true boolean isExpMonthValid = card.validateExpMonth(); // Checks if month is between 1-12 // Returns: true // Validate entire card at once boolean isCardValid = card.validateCard(); // Validates number, expiry date, and CVC together // Returns: true if (isCardValid) { // Proceed with tokenization processCard(card); } else { // Show validation errors if (!isNumberValid) { showError("Invalid card number"); } else if (!isExpiryValid) { showError("Card has expired"); } else if (!isCvcValid) { showError("Invalid security code"); } } } public void detectCardBrand() { // Detect card brand from partial or full card number String brand = CardUtils.getPossibleCardType("4242424242424242"); // Returns: "vi" (Visa) // Works with partial numbers too String partialBrand = CardUtils.getPossibleCardType("42"); // Returns: "vi" (Visa) // Supported card brands: // Card.VISA = "vi" // Card.MASTERCARD = "mc" // Card.AMERICAN_EXPRESS = "ax" // Card.DISCOVER = "dc" // Card.JCB = "jc" // Card.DINERS_CLUB = "di" // Card.EXITO = "ex" // Card.ALKOSTO = "ak" // Card.UNKNOWN = "Unknown" // Check if a card number is valid boolean isValid = CardUtils.isValidCardNumber("4242424242424242"); // Returns: true (passes Luhn check and correct length) } } ``` -------------------------------- ### Tokenize Card Data with Payment.addCard in Java Source: https://context7.com/globalpayredeban/globalpayredeban-android/llms.txt The `Payment.addCard` method securely tokenizes sensitive card data, converting it into a single-use token. This is essential for processing card information without handling raw data on your server. It requires the Android Activity context, a unique user identifier, the user's email, a `Card` object containing validated card details, and a `TokenCallback` to handle success or error responses. ```java import com.redeban.payment.Payment; import com.redeban.payment.model.Card; import com.redeban.payment.rest.TokenCallback; import com.redeban.payment.rest.model.RedebanError; public class CheckoutActivity extends AppCompatActivity { private CardMultilineWidget cardWidget; private void processPayment() { // Get card from widget (returns null if validation fails) Card cardToSave = cardWidget.getCard(); if (cardToSave == null) { Toast.makeText(this, "Invalid Card Data", Toast.LENGTH_SHORT).show(); return; } // User information for the transaction String uid = "user_12345"; // Your internal user identifier String email = "user@example.com"; // User's email address // Tokenize the card Payment.addCard(this, uid, email, cardToSave, new TokenCallback() { @Override public void onSuccess(Card card) { if (card != null) { String status = card.getStatus(); String token = card.getToken(); String transactionRef = card.getTransactionReference(); if ("valid".equals(status)) { // Card successfully tokenized Log.d("Payment", "Token: " + token); Log.d("Payment", "Transaction Ref: " + transactionRef); // Send token to your backend server sendTokenToServer(token, transactionRef); } else if ("review".equals(status)) { // Card is under fraud review showReviewDialog(token, transactionRef); } else { // Card rejected showError("Card rejected: " + card.getMessage()); } } } @Override public void onError(RedebanError error) { // Handle error Log.e("Payment", "Error Type: " + error.getType()); Log.e("Payment", "Error Help: " + error.getHelp()); Log.e("Payment", "Error Description: " + error.getDescription()); showError(error.getDescription()); } }); } private void sendTokenToServer(String token, String transactionRef) { // Send the token to your backend for charging // POST to your server: { "token": token, "transaction_reference": transactionRef } } } ``` -------------------------------- ### Customize CardMultilineWidget Attributes Source: https://github.com/globalpayredeban/globalpayredeban-android/blob/master/README.md Demonstrates how to customize the CardMultilineWidget using XML attributes. These attributes control the visibility of elements like the postal code field, Redeban logo, cardholder name, and card scanning feature. ```xml app:shouldShowPostalCode="true" app:shouldShowRedebanLogo="true" app:shouldShowCardHolderName="true" app:shouldShowScanCard="true" ``` -------------------------------- ### Handle Redeban API Errors (Java) Source: https://context7.com/globalpayredeban/globalpayredeban-android/llms.txt Implement robust error handling for Redeban API calls using the `RedebanError` class. This allows you to identify error types, provide helpful messages to developers, and display user-friendly feedback. ```java import com.redeban.payment.rest.TokenCallback; import com.redeban.payment.rest.model.RedebanError; public class ErrorHandlingExample { private void tokenizeWithErrorHandling(Card card) { Payment.addCard(this, userId, email, card, new TokenCallback() { @Override public void onSuccess(Card card) { // Handle success } @Override public void onError(RedebanError error) { // Error properties String type = error.getType(); // Error type identifier // Examples: "InvalidCard", "NetworkException", "Exception" String help = error.getHelp(); // Help text for developers // Example: "Http Code: 400" String description = error.getDescription(); // User-friendly error description // Example: "The card number is invalid" // Log detailed error info Log.e("PaymentError", String.format( "Type: %s\nHelp: %s\nDescription: %s", type, help, description )); // Show appropriate user message based on error type switch (type) { case "InvalidCard": showUserError("Please check your card details"); break; case "Network Exception": showUserError("Connection error. Please try again."); break; case "Exception": showUserError("An error occurred. Please try again."); break; default: showUserError(description); } } }); } } ``` -------------------------------- ### Payment.addCard Source: https://context7.com/globalpayredeban/globalpayredeban-android/llms.txt Tokenizes sensitive card data by converting it to a single-use token. This is the primary method for securely processing card information without handling raw card data on your server. ```APIDOC ## POST /payment/addCard ### Description Tokenizes sensitive card data by converting it to a single-use token. This is the primary method for securely processing card information without handling raw card data on your server. ### Method POST ### Endpoint /payment/addCard ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **card** (Card) - Required - The card object containing sensitive card details. - **uid** (String) - Required - Your internal user identifier. - **email** (String) - Required - User's email address. ### Request Example ```java Card cardToSave = cardWidget.getCard(); String uid = "user_12345"; String email = "user@example.com"; Payment.addCard(this, uid, email, cardToSave, new TokenCallback() { // ... callback methods ... }); ``` ### Response #### Success Response (200) - **card** (Card) - Contains the status, token, and transaction reference if the card is successfully tokenized or requires review. #### Response Example ```json { "status": "valid", "token": "tok_123abc", "transactionReference": "txn_xyz789" } ``` #### Error Response - **error** (RedebanError) - Contains details about the error encountered during tokenization. #### Error Response Example ```json { "type": "INVALID_CARD_NUMBER", "help": "Please check the card number and try again.", "description": "The provided card number is not valid." } ``` ``` -------------------------------- ### Payment.getSessionId Source: https://context7.com/globalpayredeban/globalpayredeban-android/llms.txt Generates a session ID for fraud prevention purposes. The session ID collects device information used by Redeban's anti-fraud system and should be passed to your server when creating charges. ```APIDOC ## GET /payment/getSessionId ### Description Generates a session ID for fraud prevention purposes. The session ID collects device information used by Redeban's anti-fraud system and should be passed to your server when creating charges. ### Method GET ### Endpoint /payment/getSessionId ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java String sessionId = Payment.getSessionId(this); ``` ### Response #### Success Response (200) - **sessionId** (String) - A unique identifier for the current session, used for fraud detection. #### Response Example ```json { "sessionId": "sess_abcdef123456" } ``` ``` -------------------------------- ### Generate Session ID for Fraud Prevention with Payment.getSessionId in Java Source: https://context7.com/globalpayredeban/globalpayredeban-android/llms.txt The `Payment.getSessionId` method generates a unique session ID crucial for Redeban's anti-fraud system. This ID should be collected from the device and passed to your server when initiating charges. It requires the Android Activity context as input. ```java import com.redeban.payment.Payment; public class CheckoutActivity extends AppCompatActivity { private void createChargeWithFraudPrevention() { // Get session ID for fraud detection String sessionId = Payment.getSessionId(this); // Include session ID when sending charge request to your backend JSONObject chargeRequest = new JSONObject(); try { chargeRequest.put("token", cardToken); chargeRequest.put("session_id", sessionId); chargeRequest.put("amount", 99.99); chargeRequest.put("currency", "COP"); chargeRequest.put("description", "Order #12345"); } catch (JSONException e) { e.printStackTrace(); } // Send to your backend server sendChargeRequest(chargeRequest); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.