Skip to content

Commit

Permalink
feat: add card holder information (#119)
Browse files Browse the repository at this point in the history
* feat: add cardholder information

* test: add tests with card holder data

* feat: add card holder form in CreateTokenActivity

* feat: add card holder form in AuthenticationActivity

* docs: update README to reflect card holder information

* docs: update card expiry on README

* chore: release version 4.2.0
  • Loading branch information
azaky authored Aug 7, 2024
1 parent 934967e commit 366f285
Show file tree
Hide file tree
Showing 17 changed files with 502 additions and 166 deletions.
7 changes: 2 additions & 5 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# CHANGELOG

## 4.2.0 (2024-08-06)
- Feat: Added card holder information in create token and create authentication

## 4.1.2 (2024-05-27)
- fix JCB card detection and expiry date
- Fix JCB card detection and expiry date

## 4.1.1 (20240-01-26)
- Support mid_label in create token and unbundled create authentication
Expand Down
45 changes: 24 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ Maven:
<dependency>
<groupId>com.xendit</groupId>
<artifactId>xendit-android</artifactId>
<version>4.1.2</version>
<version>4.2.0</version>
<type>pom</type>
</dependency>
```

Gradle:
```
compile 'com.xendit:xendit-android:4.1.2'
compile 'com.xendit:xendit-android:4.2.0'
```

Ivy:
```
<dependency org='com.xendit' name='xendit-android' rev='4.1.2'>
<dependency org='com.xendit' name='xendit-android' rev='4.2.0'>
<artifact name='xendit-android' ext='pom' ></artifact>
</dependency>
```

For more information, visit https://central.sonatype.dev/artifact/com.xendit/xendit-android/4.1.2/versions
For more information, visit https://central.sonatype.com/artifact/com.xendit/xendit-android/4.2.0/versions

**Note**:

Expand Down Expand Up @@ -103,8 +103,9 @@ This function accepts parameters below:
|midLabel|String|*For switcher merchant only* Specific string value which labels any of your Merchant IDs (MID) set up with Xendit. This can be configured in the list of MIDs on your Dashboard settings. (If this is not included in a request, and you have more than 1 MID in your list, the transaction will proceed using your prioritized MID (first MID on your list)).|


```
Card card = new Card("4000000000001091", "12", "2017", "123");
```java
CardHolderData cardHolderData = new CardHolderData("John", "Doe", "johndoe@example.com", "+628212223242526");
Card card = new Card("4000000000001091", "12", "2039", "123", cardHolderData);

xendit.createSingleUseToken(card, 75000, true, "user-id", billingDetails, customer, currency, midLabel, new TokenCallback() {
@Override
Expand All @@ -129,8 +130,9 @@ xendit.createSingleUseToken(card, 75000, true, "user-id", billingDetails, custom
|customer|customer object|Xendit customer object|
|midLabel|String|*For switcher merchant only* Specific string value which labels any of your Merchant IDs (MID) set up with Xendit. This can be configured in the list of MIDs on your Dashboard settings. (If this is not included in a request, and you have more than 1 MID in your list, the transaction will proceed using your prioritized MID (first MID on your list)).|

```
Card card = new Card("4000000000001091", "12", "2017", "123");
```java
CardHolderData cardHolderData = new CardHolderData("John", "Doe", "johndoe@example.com", "+628212223242526");
Card card = new Card("4000000000001091", "12", "2039", "123");

xendit.createMultipleUseToken(card, "user-id", billingDetails, customer, midLabel, new TokenCallback() {
@Override
Expand All @@ -147,21 +149,22 @@ xendit.createMultipleUseToken(card, "user-id", billingDetails, customer, midLabe
```

### Creating a 3DS authentication
|Parameter|Type|Description|
|---------|----|-----------|
|tokenId|String|a multiple-use token ID that is already created|
|amount|String|Amount that will be used to create a token bundled with 3DS authentication|
|currency|String|Currency of the transaction that will be submitted for 3DS authentication|
|cardCvn|String|Card verification Number collected from card holder|
|midLabel|String|*For switcher merchant only* Specific string value which labels any of your Merchant IDs (MID) set up with Xendit. This can be configured in the list of MIDs on your Dashboard settings. (If this is not included in a request, and you have more than 1 MID in your list, the transaction will proceed using your prioritized MID (first MID on your list)).|
|onBehalfOf|String| Sub-account business ID for XenPlatform master account who intended to create a token for their sub-account. Will be set to `empty` if you omit the parameter|
|midLabel|String|*For switcher merchant only* Specific string value which labels any of your Merchant IDs (MID) set up with Xendit. This can be configured in the list of MIDs on your Dashboard settings. (If this is not included in a request, and you have more than 1 MID in your list, the transaction will proceed using your prioritized MID (first MID on your list)).|

```
| Parameter |Type|Description|
|----------------|----|-----------|
| tokenId |String|a multiple-use token ID that is already created|
| amount |String|Amount that will be used to create a token bundled with 3DS authentication|
| currency |String|Currency of the transaction that will be submitted for 3DS authentication|
| cardCvn |String|Card verification Number collected from card holder|
| cardHolderData |String|Additional information of the card holder data|
| midLabel |String|*For switcher merchant only* Specific string value which labels any of your Merchant IDs (MID) set up with Xendit. This can be configured in the list of MIDs on your Dashboard settings. (If this is not included in a request, and you have more than 1 MID in your list, the transaction will proceed using your prioritized MID (first MID on your list)).|
| onBehalfOf |String| Sub-account business ID for XenPlatform master account who intended to create a token for their sub-account. Will be set to `empty` if you omit the parameter|

```java
String tokenId = "sample-token-id";
int amount = 50000;
CardHolderData cardHolderData = new CardHolderData("John", "Doe", "johndoe@example.com", "+628212223242526");

xendit.createAuthentication(tokenId, amount, currency, cardCvn, "user-id", midLabel, new AuthenticationCallback() {
xendit.createAuthentication(tokenId, amount, currency, cardCvn, cardHolderData, "user-id", midLabel, new AuthenticationCallback() {
@Override
public void onSuccess(Authentication authentication) {
// Handle successful authentication
Expand All @@ -179,7 +182,7 @@ xendit.createAuthentication(tokenId, amount, currency, cardCvn, "user-id", midLa
When you're ready to charge a card, use the private key on your backend to call the charge endpoint. See our API reference at https://xendit.github.io/apireference/#create-charge


## Compability with ProGuard
## Compatibility with ProGuard

You will need to add the following to your proguard rules file (`proguard-rules.pro`). Else, proguard might affect deserialization of the authentication response body.
```
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/xendit/example/AuthenticationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class AuthenticationActivity extends AppCompatActivity implements View.On
private EditText tokenIdEditText;
private EditText amountEditText;
private EditText cardCvnEditText;
private EditText cardHolderFirstNameEditText;
private EditText cardHolderLastNameEditText;
private EditText cardHolderEmailEditText;
private EditText cardHolderPhoneNumberEditText;
private EditText midLabelText;
private Button authenticateBtn;
private TextView resultTextView;
Expand All @@ -49,13 +53,21 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
tokenIdEditText = (EditText) findViewById(R.id.tokenIdEditText_AuthenticationActivity);
amountEditText = (EditText) findViewById(R.id.amountEditText_AuthenticationActivity);
cardCvnEditText = (EditText) findViewById(R.id.cardCvnEditText_AuthenticationActivity);
cardHolderFirstNameEditText = (EditText) findViewById(R.id.cardHolderFirstNameEditText_AuthenticationActivity);
cardHolderLastNameEditText = (EditText) findViewById(R.id.cardHolderLastNameEditText_AuthenticationActivity);
cardHolderEmailEditText = (EditText) findViewById(R.id.cardHolderEmailEditText_AuthenticationActivity);
cardHolderPhoneNumberEditText = (EditText) findViewById(R.id.cardHolderPhoneNumberEditText_AuthenticationActivity);
midLabelText = (EditText) findViewById(R.id.midLabelEditText_AuthenticationActivity);

authenticateBtn = (Button) findViewById(R.id.authenticateBtn_AuthenticationActivity);
resultTextView = (TextView) findViewById(R.id.result_AuthenticationActivity);

amountEditText.setText(getString(R.string.amountTest));
cardCvnEditText.setText(getString(R.string.cvnTest));
cardHolderFirstNameEditText.setText(R.string.cardHolderFirstNameTest);
cardHolderLastNameEditText.setText(R.string.cardHolderLastNameTest);
cardHolderEmailEditText.setText(R.string.cardHolderEmailTest);
cardHolderPhoneNumberEditText.setText(R.string.cardHolderPhoneNumberTest);

authenticateBtn.setOnClickListener(this);
}
Expand Down
29 changes: 24 additions & 5 deletions app/src/main/java/com/xendit/example/CreateTokenActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.xendit.Models.Address;
import com.xendit.Models.BillingDetails;
import com.xendit.Models.Card;
import com.xendit.Models.CardHolderData;
import com.xendit.Models.CardInfo;
import com.xendit.Models.Customer;
import com.xendit.Models.Token;
Expand All @@ -45,6 +46,10 @@ public class CreateTokenActivity extends AppCompatActivity implements View.OnCli
private EditText expYearEditText;
private EditText cvnEditText;
private EditText amountEditText;
private EditText cardHolderFirstNameEditText;
private EditText cardHolderLastNameEditText;
private EditText cardHolderEmailEditText;
private EditText cardHolderPhoneNumberEditText;
private EditText midLabelText;
private Button createTokenBtn;
private CheckBox multipleUseCheckBox;
Expand Down Expand Up @@ -72,6 +77,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
expYearEditText = (EditText) findViewById(R.id.expYearEditText_CreateTokenActivity);
cvnEditText = (EditText) findViewById(R.id.cvnEditText_CreateTokenActivity);
amountEditText = (EditText) findViewById(R.id.amountEditText_CreateTokenActivity);
cardHolderFirstNameEditText = (EditText) findViewById(R.id.cardHolderFirstNameEditText_CreateTokenActivity);
cardHolderLastNameEditText = (EditText) findViewById(R.id.cardHolderLastNameEditText_CreateTokenActivity);
cardHolderEmailEditText = (EditText) findViewById(R.id.cardHolderEmailEditText_CreateTokenActivity);
cardHolderPhoneNumberEditText = (EditText) findViewById(R.id.cardHolderPhoneNumberEditText_CreateTokenActivity);
midLabelText = (EditText) findViewById(R.id.midLabelEditText_CreateTokenActivity);

createTokenBtn = (Button) findViewById(R.id.createTokenBtn_CreateTokenActivity);
Expand All @@ -87,6 +96,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
expYearEditText.setText(year);
cvnEditText.setText(R.string.cvnTest);
amountEditText.setText(R.string.amountTest);
cardHolderFirstNameEditText.setText(R.string.cardHolderFirstNameTest);
cardHolderLastNameEditText.setText(R.string.cardHolderLastNameTest);
cardHolderEmailEditText.setText(R.string.cardHolderEmailTest);
cardHolderPhoneNumberEditText.setText(R.string.cardHolderPhoneNumberTest);
}

private void setActionBarTitle(String title) {
Expand All @@ -108,10 +121,16 @@ public void onClick(View view) {
isMultipleUse = multipleUseCheckBox.isChecked();
shouldAuthenticate = !shouldAuthenticateCheckBox.isChecked();

CardHolderData cardHolderData = new CardHolderData(cardHolderFirstNameEditText.getText().toString(),
cardHolderLastNameEditText.getText().toString(),
cardHolderEmailEditText.getText().toString(),
cardHolderPhoneNumberEditText.getText().toString());

Card card = new Card(cardNumberEditText.getText().toString(),
expMonthEditText.getText().toString(),
expYearEditText.getText().toString(),
cvnEditText.getText().toString());
cvnEditText.getText().toString(),
cardHolderData);

Address billingAddress = new Address();
billingAddress.setCountry("ID");
Expand All @@ -123,22 +142,22 @@ public void onClick(View view) {
billingAddress.setPostalCode("123123");

BillingDetails billingDetails = new BillingDetails();
billingDetails.setMobileNumber("+6208123123123");
billingDetails.setMobileNumber("+628123123123");
billingDetails.setEmail("john@xendit.co");
billingDetails.setGivenNames("John");
billingDetails.setSurname("Hudson");
billingDetails.setPhoneNumber("+6208123123123");
billingDetails.setPhoneNumber("+628123123123");
billingDetails.setAddress(billingAddress);

Address shippingAddress = billingAddress;
Address[] customerAddress = { shippingAddress };

Customer customer = new Customer();
customer.setMobileNumber("+6208123123123");
customer.setMobileNumber("+628123123123");
customer.setEmail("john@xendit.co");
customer.setGivenNames("John");
customer.setSurname("Hudson");
customer.setPhoneNumber("+6208123123123");
customer.setPhoneNumber("+628123123123");
customer.setNationality("ID");
customer.setDateOfBirth("1990-04-13");
customer.setDescription("test user");
Expand Down
51 changes: 51 additions & 0 deletions app/src/main/res/layout/activity_authentication.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,57 @@
android:textColorHint="#cccccc"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">

<EditText
android:id="@+id/cardHolderFirstNameEditText_AuthenticationActivity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:hint="First Name"
android:inputType="text|textPersonName"
android:textColor="@android:color/black"
android:textColorHint="#cccccc" />

<EditText
android:id="@+id/cardHolderLastNameEditText_AuthenticationActivity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:hint="Last Name"
android:inputType="text|textPersonName"
android:textColor="@android:color/black"
android:textColorHint="#cccccc" />
</LinearLayout>

<EditText
android:id="@+id/cardHolderEmailEditText_AuthenticationActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Email"
android:inputType="text|textWebEmailAddress"
android:textColor="@android:color/black"
android:textColorHint="#cccccc" />

<EditText
android:id="@+id/cardHolderPhoneNumberEditText_AuthenticationActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Phone Number"
android:inputType="text"
android:textColor="@android:color/black"
android:textColorHint="#cccccc" />

<EditText
android:id="@+id/midLabelEditText_AuthenticationActivity"
android:layout_width="match_parent"
Expand Down
51 changes: 51 additions & 0 deletions app/src/main/res/layout/activity_create_token.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,57 @@
android:textColor="@android:color/black"
android:textColorHint="#cccccc" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">

<EditText
android:id="@+id/cardHolderFirstNameEditText_CreateTokenActivity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:hint="First Name"
android:inputType="text|textPersonName"
android:textColor="@android:color/black"
android:textColorHint="#cccccc" />

<EditText
android:id="@+id/cardHolderLastNameEditText_CreateTokenActivity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:hint="Last Name"
android:inputType="text|textPersonName"
android:textColor="@android:color/black"
android:textColorHint="#cccccc" />
</LinearLayout>

<EditText
android:id="@+id/cardHolderEmailEditText_CreateTokenActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Email"
android:inputType="text|textWebEmailAddress"
android:textColor="@android:color/black"
android:textColorHint="#cccccc" />

<EditText
android:id="@+id/cardHolderPhoneNumberEditText_CreateTokenActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Phone Number"
android:inputType="text"
android:textColor="@android:color/black"
android:textColorHint="#cccccc" />

<EditText
android:id="@+id/midLabelEditText_CreateTokenActivity"
android:layout_width="match_parent"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<string name="expMonthTest">12</string>
<string name="cvnTest">123</string>
<string name="amountTest">123000</string>
<string name="cardHolderFirstNameTest">John</string>
<string name="cardHolderLastNameTest">Hudson</string>
<string name="cardHolderEmailTest">john@xendit.co</string>
<string name="cardHolderPhoneNumberTest">+628123123123</string>
<string name="create_token">Create Token</string>
<string name="store_cvn">Store CVN</string>
</resources>
Loading

0 comments on commit 366f285

Please sign in to comment.