1
+ package com .xendit .example ;
2
+
3
+ import static com .xendit .example .CreateTokenActivity .PUBLISHABLE_KEY ;
4
+
5
+ import android .content .Context ;
6
+ import android .content .Intent ;
7
+ import android .os .Bundle ;
8
+ import android .util .Log ;
9
+ import android .view .MenuItem ;
10
+ import android .view .View ;
11
+ import android .widget .Button ;
12
+ import android .widget .EditText ;
13
+ import android .widget .ProgressBar ;
14
+ import android .widget .TextView ;
15
+ import android .widget .Toast ;
16
+
17
+ import androidx .appcompat .app .ActionBar ;
18
+ import androidx .appcompat .app .AppCompatActivity ;
19
+
20
+ import com .google .gson .Gson ;
21
+ import com .xendit .Models .Address ;
22
+ import com .xendit .Models .BillingDetails ;
23
+ import com .xendit .Models .Customer ;
24
+ import com .xendit .Models .Token ;
25
+ import com .xendit .Models .XenditError ;
26
+ import com .xendit .Xendit ;
27
+ import com .xendit .example .models .StoreCVNResponse ;
28
+ import com .xendit .example .models .TokenizationResponse ;
29
+ import com .xendit .utils .StoreCVNCallback ;
30
+
31
+ public class StoreCvnActivity extends AppCompatActivity implements View .OnClickListener {
32
+ public static final String DUMMY_PUBLISHABLE_KEY = "xnd_public_development_O4uGfOR3gbOunJU4frcaHmLCYNLy8oQuknDm+R1r9G3S/b2lBQR+gQ==" ;
33
+
34
+ private EditText tokenId ;
35
+ private EditText cardCVN ;
36
+ private Button storeCVNBtn ;
37
+ private TextView storeCVNResult ;
38
+
39
+ @ Override
40
+ protected void onCreate (Bundle savedInstanceState ) {
41
+ super .onCreate (savedInstanceState );
42
+ setContentView (R .layout .activity_store_cvn );
43
+ setActionBarTitle (getString (R .string .store_cvn ));
44
+
45
+ // Bind UI Component to class fields
46
+ tokenId = (EditText ) findViewById (R .id .tokenIdEditText_StoreCVNActivity );
47
+ cardCVN = (EditText ) findViewById (R .id .cvnEditText_StoreCVNActivity );
48
+ storeCVNBtn = (Button ) findViewById (R .id .btnStoreCVN );
49
+ storeCVNResult = (TextView ) findViewById (R .id .result_storeCVNActivity );
50
+
51
+ storeCVNBtn .setOnClickListener (this );
52
+ }
53
+
54
+ private void setActionBarTitle (String title ) {
55
+ ActionBar actionBar = getSupportActionBar ();
56
+ if (actionBar != null ) {
57
+ actionBar .setTitle (title );
58
+ actionBar .setDisplayHomeAsUpEnabled (true );
59
+ actionBar .setHomeButtonEnabled (true );
60
+ }
61
+ }
62
+
63
+ @ Override
64
+ public void onClick (View view ) {
65
+ final Xendit xendit = new Xendit (getApplicationContext (), DUMMY_PUBLISHABLE_KEY , this );
66
+
67
+ final ProgressBar progressBar = findViewById (R .id .progressBar );
68
+ progressBar .setVisibility (View .VISIBLE );
69
+
70
+ // Dummy data
71
+ Address billingAddress = new Address ();
72
+ billingAddress .setCountry ("ID" );
73
+ billingAddress .setStreetLine1 ("Panglima Polim IV" );
74
+ billingAddress .setStreetLine2 ("Ruko Grand Panglima Polim, Blok E" );
75
+ billingAddress .setCity ("Jakarta Selatan" );
76
+ billingAddress .setProvinceState ("DKI Jakarta" );
77
+ billingAddress .setCategory ("WORK" );
78
+ billingAddress .setPostalCode ("123123" );
79
+
80
+ BillingDetails billingDetails = new BillingDetails ();
81
+ billingDetails .setMobileNumber ("+6208123123123" );
82
+ billingDetails .
setEmail (
"[email protected] " );
83
+ billingDetails .setGivenNames ("John" );
84
+ billingDetails .setSurname ("Hudson" );
85
+ billingDetails .setPhoneNumber ("+6208123123123" );
86
+ billingDetails .setAddress (billingAddress );
87
+
88
+ Address shippingAddress = billingAddress ;
89
+ Address [] customerAddress = { shippingAddress };
90
+
91
+ Customer customer = new Customer ();
92
+ customer .setMobileNumber ("+6208123123123" );
93
+ customer .
setEmail (
"[email protected] " );
94
+ customer .setGivenNames ("John" );
95
+ customer .setSurname ("Hudson" );
96
+ customer .setPhoneNumber ("+6208123123123" );
97
+ customer .setNationality ("ID" );
98
+ customer .setDateOfBirth ("1990-04-13" );
99
+ customer .setDescription ("test user" );
100
+ customer .setAddresses (customerAddress );
101
+
102
+ StoreCVNCallback callback = new StoreCVNCallback () {
103
+ @ Override
104
+ public void onSuccess (Token token ) {
105
+ progressBar .setVisibility (View .GONE );
106
+ Gson gson = new Gson ();
107
+ StoreCVNResponse storeCVNResponse = new StoreCVNResponse (token );
108
+ String json = gson .toJson (storeCVNResponse );
109
+ storeCVNResult .setText (json );
110
+ Log .d ("STORE_CVN_SUCCESS" , json .toString ());
111
+ Toast .makeText (StoreCvnActivity .this , "Store CVN Successful" , Toast .LENGTH_SHORT ).show ();
112
+ }
113
+
114
+ @ Override
115
+ public void onError (XenditError xenditError ) {
116
+ progressBar .setVisibility (View .GONE );
117
+ Log .d ("STORE_CVN_FAILED" , xenditError .toString ());
118
+ Toast .makeText (StoreCvnActivity .this , xenditError .getErrorCode () + " " +
119
+ xenditError .getErrorMessage (), Toast .LENGTH_SHORT ).show ();
120
+ }
121
+ };
122
+
123
+ xendit .storeCVN (tokenId .getText ().toString (), cardCVN .getText ().toString (), billingDetails , customer , "" , callback );
124
+ }
125
+
126
+ @ Override
127
+ public boolean onOptionsItemSelected (MenuItem item ) {
128
+ switch (item .getItemId ()) {
129
+ case android .R .id .home :
130
+ this .finish ();
131
+ return true ;
132
+ default :
133
+ return super .onOptionsItemSelected (item );
134
+ }
135
+ }
136
+
137
+ public static Intent getLaunchIntent (Context context ) {
138
+ return new Intent (context , StoreCvnActivity .class );
139
+ }
140
+ }
0 commit comments