2626import net .authorize .aim .emv .EMVTransactionManager ;
2727import net .authorize .auth .PasswordAuthentication ;
2828import net .authorize .auth .SessionTokenAuthentication ;
29+ import net .authorize .auth .TransactionKeyAuthentication ;
2930import net .authorize .data .Order ;
3031import net .authorize .data .OrderItem ;
3132import net .authorize .data .creditcard .CreditCard ;
3940public class LoginActivity extends FragmentActivity {
4041 Button b ;
4142 EditText login ;
42- EditText pwd ;
43+ EditText transactionKey ;
4344 Context context ;
4445 Environment environment = Environment .SANDBOX ;
4546 RadioGroup radioGroup ;
@@ -55,7 +56,7 @@ protected void onCreate(Bundle savedInstanceState) {
5556 b .setOnClickListener (mListner );
5657
5758 login = (EditText )findViewById (R .id .editTextLoginLoginID );
58- pwd = (EditText )findViewById (R .id .editTextLoginPassword );
59+ transactionKey = (EditText )findViewById (R .id .editTextLoginPassword );
5960
6061 radioGroup = (RadioGroup ) findViewById (R .id .login_type_radio_group );
6162 testButton = (RadioButton ) findViewById (R .id .test_radio_button );
@@ -111,52 +112,22 @@ public void onClick(View view){
111112 @ Override
112113 public void run (){
113114
114- // handler.sendEmptyMessage(0);
115- net .authorize .mobile .Result result ;
116- String deviceID = "Test EMV Android" ;
117- PasswordAuthentication passAuth = PasswordAuthentication
118- .createMerchantAuthentication (login .getText ().toString (), pwd .getText ().toString (), deviceID );
119-
120- AppManager .merchant = Merchant .createMerchant (environment , passAuth );
121-
122- net .authorize .mobile .Transaction transaction = AppManager .merchant
123- .createMobileTransaction (net .authorize .mobile .TransactionType .MOBILE_DEVICE_LOGIN );
124- MobileDevice mobileDevice = MobileDevice .createMobileDevice (deviceID ,
125- "Device description" , "425-555-0000" , "Android" );
126- transaction .setMobileDevice (mobileDevice );
127-
128- Gson gson = new GsonBuilder ().setPrettyPrinting ().create ();
129- String transactionJson = gson .toJson (transaction );
130- Log .d ("LoginRequest" , "Sending request: " + transactionJson );
131-
132- result = (net .authorize .mobile .Result ) AppManager .merchant
133- .postTransaction (transaction );
134-
135- // Log incoming response
136- Log .d ("LoginResponse" , "Received response: " + result .getXmlResponse ());
137-
138- if (result .isOk ()){
139-
140- try {
141- SessionTokenAuthentication sessionTokenAuthentication = SessionTokenAuthentication
142- .createMerchantAuthentication (AppManager .merchant
143- .getMerchantAuthentication ().getName (), result
144- .getSessionToken (), "Test EMV Android" );
145- if ((result .getSessionToken () != null )
146- && (sessionTokenAuthentication != null )) {
147- AppManager .merchant
148- .setMerchantAuthentication (sessionTokenAuthentication );
149-
150- handler .sendEmptyMessage (0 );
151- }
152- } catch (Exception ex ) {
153- Log .e ("loginException" , "Exception: " + ex .getMessage ());
154- }
155- }
156- else {
115+ try {
116+ // Use TransactionKeyAuthentication (no session token needed)
117+ TransactionKeyAuthentication merchantAuth = TransactionKeyAuthentication
118+ .createMerchantAuthentication (login .getText ().toString (), transactionKey .getText ().toString ());
119+
120+ AppManager .merchant = Merchant .createMerchant (environment , merchantAuth );
121+
122+ Log .d ("LoginInfo" , "Using Transaction Key Authentication" );
123+
124+ // Transaction key authentication doesn't require a login transaction
125+ // Authentication is validated on the first actual transaction
126+ handler .sendEmptyMessage (0 );
127+
128+ } catch (Exception ex ) {
129+ Log .e ("loginException" , "Exception: " + ex .getMessage ());
157130 handler .sendEmptyMessage (1 );
158- Log .e ("EMVResponse" ,result .getXmlResponse ());
159- // Toast.makeText(context, result.getXmlResponse(),Toast.LENGTH_SHORT).show();
160131 }
161132
162133 }
0 commit comments