() {
107 | @Override
108 | public void onDeviceSelected(Device device) {
109 | currentDevice = device;
110 | selectDeviceDelegate.onDeviceSelected(currentDevice);
111 | }
112 |
113 | @Override
114 | public void onSelectionCanceled() {
115 | finish();
116 | }
117 | });
118 | }
119 | });
120 | }
121 | };
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/demo/demo/sample/src/flavor_thyronUsb/res/layout/activity_firmware_update.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
12 |
13 |
22 |
23 |
32 |
33 |
39 |
40 |
--------------------------------------------------------------------------------
/demo/demo/sample/src/flavor_thyronUsb/res/layout/activity_menu.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
13 |
18 |
23 |
28 |
33 |
38 |
43 |
48 |
53 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/demo/demo/sample/src/flavor_thyronUsb/res/values/config_for_accept.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | - true
4 | - true
5 |
6 |
7 | - SpireExtension
8 |
9 |
--------------------------------------------------------------------------------
/demo/demo/sample/src/flavor_thyronUsb/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Accept Sample App - Thyron USB
5 | Updating the firmware from %1$s to %2$s ...
6 | Done
7 |
--------------------------------------------------------------------------------
/demo/demo/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
17 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
31 |
35 |
39 |
43 |
47 |
51 |
55 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/demo/demo/sample/src/main/java/de/wirecard/accept/sample/AbstractMenuActivity.java:
--------------------------------------------------------------------------------
1 | package de.wirecard.accept.sample;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import de.wirecard.accept.sdk.AcceptSDK;
10 | import de.wirecard.accept.sdk.extensions.Device;
11 |
12 | /**
13 | * @linc MenuActivity.java
14 | */
15 | public abstract class AbstractMenuActivity extends BaseActivity {
16 |
17 | abstract void discoverDevices();
18 |
19 | protected Device currentUsedDevice;
20 |
21 | public static Intent intent(final Context context) {
22 | return new Intent(context, MenuActivity.class);
23 | }
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_menu);
29 |
30 | Button discoverDevicesButton = (Button) findViewById(R.id.discoverDevices);
31 | if (discoverDevicesButton != null) {
32 | discoverDevicesButton.setOnClickListener(new View.OnClickListener() {
33 | @Override
34 | public void onClick(View v) {
35 | currentUsedDevice = null; //because we will not use remembered one
36 | discoverDevices();
37 | }
38 | });
39 | }
40 |
41 | findViewById(R.id.payment).setOnClickListener(new View.OnClickListener() {
42 | @Override
43 | public void onClick(View v) {
44 | startActivity(PaymentFlowActivity.intent(getApplicationContext()));
45 | }
46 | });
47 |
48 | findViewById(R.id.history).setOnClickListener(new View.OnClickListener() {
49 | @Override
50 | public void onClick(View v) {
51 | startActivity(TransactionsHistoryActivity.intent(getApplicationContext()));
52 | }
53 | });
54 |
55 | findViewById(R.id.logout).setOnClickListener(new View.OnClickListener() {
56 | @Override
57 | public void onClick(View v) {
58 | logOut();
59 | }
60 | });
61 |
62 | }
63 |
64 | protected void logOut(){
65 | AcceptSDK.logout();
66 | startActivity(new Intent(AbstractMenuActivity.this, LoginActivity.class));
67 | finish();
68 | }
69 |
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/demo/demo/sample/src/main/java/de/wirecard/accept/sample/AbstractPaymentFlowActivity.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015 Wirecard. All rights reserved.
3 | *
4 | * Accept SDK for Android
5 | */
6 | package de.wirecard.accept.sample;
7 |
8 | import android.content.Context;
9 | import android.content.Intent;
10 | import android.os.Bundle;
11 | import android.text.Editable;
12 | import android.text.TextWatcher;
13 | import android.view.View;
14 | import android.view.WindowManager;
15 | import android.view.inputmethod.InputMethodManager;
16 | import android.widget.Button;
17 | import android.widget.EditText;
18 | import android.widget.TextView;
19 | import android.widget.Toast;
20 |
21 | import java.math.BigDecimal;
22 | import java.util.Currency;
23 | import java.util.Locale;
24 |
25 | import de.wirecard.accept.sdk.AcceptSDK;
26 | import de.wirecard.accept.sdk.model.CashBackItem;
27 | import de.wirecard.accept.sdk.model.Payment;
28 | import de.wirecard.accept.sdk.model.PaymentItem;
29 |
30 | /**
31 | * Basic payment flow controlling activity
32 | */
33 | public abstract class AbstractPaymentFlowActivity extends BaseActivity {
34 |
35 | final String TAG = this.getClass().getSimpleName();
36 | private Button payButton;
37 | private Currency amountCurrency;
38 | private EditText amountTextView;
39 | private BigDecimal currentAmount = BigDecimal.ZERO;
40 | protected AcceptSDK.CashBack cashBack = AcceptSDK.CashBack.off;
41 | private Button subMerchInfo;
42 | private Button additionalFields;
43 | protected boolean isDestroyed = false; // To support Android 4.2, 4.2.2 ( < API 17 ).
44 |
45 | //abstract methods
46 | protected abstract void onPayButtonClick();
47 |
48 | public static Intent intent(final Context context) {
49 | return new Intent(context, PaymentFlowActivity.class);
50 | }
51 |
52 | public Currency getAmountCurrency() {
53 | return amountCurrency;
54 | }
55 |
56 | public BigDecimal getCurrentAmount() {
57 | return currentAmount;
58 | }
59 |
60 | @Override
61 | protected void onCreate(Bundle savedInstanceState) {
62 | super.onCreate(savedInstanceState);
63 | setContentView(R.layout.activity_payment);
64 |
65 | subMerchInfo = (Button) findViewById(R.id.sub_merch_info);
66 | if (getResources().getBoolean(R.bool.demo_allow_sub_merchant_info)) {
67 | subMerchInfo.setOnClickListener(new View.OnClickListener() {
68 | @Override
69 | public void onClick(View v) {
70 | startActivity(new Intent(AbstractPaymentFlowActivity.this, SubMerchantInfoActivity.class));
71 | }
72 | });
73 | } else {
74 | subMerchInfo.setVisibility(View.GONE);
75 | }
76 | //hide additional fields when not enabled
77 | additionalFields = (Button) findViewById(R.id.additional_fields);
78 | if (!getResources().getBoolean(R.bool.demo_allow_additional_payment_fields)) {
79 | additionalFields.setVisibility(View.GONE);
80 | } else {
81 | additionalFields.setOnClickListener(new View.OnClickListener() {
82 | @Override
83 | public void onClick(View v) {
84 | startActivity(new Intent(AbstractPaymentFlowActivity.this, AdditionalPaymentFieldsActivity.class));
85 | }
86 | });
87 | }
88 | amountCurrency = Currency.getInstance(AcceptSDK.getCurrency());
89 | amountTextView = (EditText) findViewById(R.id.amount);
90 | amountTextView.addTextChangedListener(new TextWatcher() {
91 | @Override
92 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {
93 |
94 | }
95 |
96 | @Override
97 | public void onTextChanged(CharSequence s, int start, int before, int count) {
98 |
99 | }
100 |
101 | @Override
102 | public void afterTextChanged(Editable s) {
103 | if (s.toString().isEmpty())
104 | return;
105 | try {
106 | String amount = s.toString().replaceAll("[" + amountCurrency.getSymbol(Locale.getDefault()) + "]", "").replaceAll("\\s+", "").replace(',', '.');
107 | currentAmount = new BigDecimal(amount);
108 | } catch (NumberFormatException e) {
109 | currentAmount = BigDecimal.ONE;
110 | Toast.makeText(AbstractPaymentFlowActivity.this, "Invalid number format", Toast.LENGTH_LONG).show();
111 | }
112 | }
113 | });
114 | //amountTextView.setText(CurrencyUtils.format(150, amountCurrency, Locale.getDefault()));
115 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
116 |
117 | payButton = (Button) findViewById(R.id.payButton);
118 | payButton.setOnClickListener(new View.OnClickListener() {
119 | @Override
120 | public void onClick(View v) {
121 | if (beforePayment()) return;
122 | //payment specific behaviour
123 | onPayButtonClick();
124 | }
125 | }
126 | );
127 |
128 | //registerReceiver(screenOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
129 | isDestroyed = false;
130 |
131 | hideKeyboard();
132 | AcceptSDK.startPayment();// initialization of new payment in SDK
133 | }
134 |
135 | /**
136 | * do stuff that is common for cash and all card payment
137 | * @return return true if validation fails
138 | */
139 | private boolean beforePayment() {
140 | if (currentAmount == null || BigDecimal.ZERO.equals(currentAmount)) {
141 | Toast.makeText(AbstractPaymentFlowActivity.this, "Invalid amount", Toast.LENGTH_SHORT).show();
142 | return true;
143 | }
144 | disablePaymentControls();
145 |
146 | hideKeyboard();
147 |
148 | // Payment item object preparation
149 | if (cashBack == AcceptSDK.CashBack.off) {
150 | Float tax;// prepare tax parameter for payment item
151 | if (AcceptSDK.getPrefTaxArray().isEmpty())//if not filled out use "0f"
152 | tax = 0f;
153 | else
154 | tax = AcceptSDK.getPrefTaxArray().get(0);// taxes are defined on backend and requested during communication..pls use only your "supported" values
155 |
156 | //here is example how to add one payment item to basket
157 | //payment item is instance of MoneyDisplayItem
158 | AcceptSDK.addPaymentItem(new PaymentItem(1, "", getCurrentAmount(), tax));
159 | //for demonstration we are using only one item to be able to fully controll amount from simple UI.
160 | }
161 | else {
162 | //CashBack Item is just different instance of MoneyDisplayItem
163 | AcceptSDK.setCashBackItem(new CashBackItem("CashBack item note", currentAmount));
164 | }
165 |
166 | //hide additional fields during payment
167 | if (getResources().getBoolean(R.bool.demo_allow_additional_payment_fields)) {
168 | additionalFields.setVisibility(View.GONE);
169 | }
170 | //hide subMerchantInfo during payment
171 | if (getResources().getBoolean(R.bool.demo_allow_sub_merchant_info)) {
172 | subMerchInfo.setVisibility(View.GONE);
173 | }
174 |
175 | return false;
176 | }
177 |
178 | protected void disablePaymentControls() {
179 | amountTextView.setEnabled(false);
180 | payButton.setEnabled(false);
181 | }
182 |
183 | @Override
184 | public void onBackPressed() {
185 | super.onBackPressed();
186 | }
187 |
188 | protected void runOnUiThreadIfNotDestroyed(final Runnable runnable) {
189 | if (!isDestroyed) runOnUiThread(runnable);
190 | }
191 |
192 | protected void showResultSection(final boolean success) {
193 | runOnUiThreadIfNotDestroyed(new Runnable() {
194 | @Override
195 | public void run() {
196 | ((TextView) findViewById(R.id.status)).setText(getString(success ?
197 | R.string.acceptsdk_progress__sucesful : R.string.acceptsdk_progress__declined));
198 | findViewById(R.id.progress_section).setVisibility(View.GONE);
199 | findViewById(R.id.signature_section).setVisibility(View.GONE);
200 | disablePaymentControls();
201 | }
202 | });
203 | }
204 |
205 | protected void showProgress(final int messageRes, final boolean showProgress) {
206 | showProgress(messageRes == -1 ? "" : getString(messageRes), showProgress);
207 | }
208 |
209 | protected void showProgress(final String message, final boolean showProgress) {
210 | runOnUiThreadIfNotDestroyed(new Runnable() {
211 | @Override
212 | public void run() {
213 | findViewById(R.id.progress_section).setVisibility(View.VISIBLE);
214 | findViewById(R.id.progress).setVisibility(showProgress ? View.VISIBLE : View.INVISIBLE);
215 | ((TextView) findViewById(R.id.status)).setText(message);
216 | findViewById(R.id.signature_section).setVisibility(View.GONE);
217 | }
218 | });
219 | }
220 |
221 | public void hideKeyboard() {
222 | InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
223 | imm.hideSoftInputFromWindow(this.getWindow().getDecorView().getWindowToken(), 0);
224 | }
225 |
226 | protected void showReceipt(Payment payment){
227 | Receipt receipt = new Receipt(this);
228 | receipt.showReceipt(payment);
229 | }
230 | }
--------------------------------------------------------------------------------
/demo/demo/sample/src/main/java/de/wirecard/accept/sample/AdditionalPaymentFieldsActivity.java:
--------------------------------------------------------------------------------
1 | package de.wirecard.accept.sample;
2 |
3 | import android.os.Bundle;
4 | import android.support.design.widget.TextInputLayout;
5 | import android.widget.EditText;
6 |
7 | import java.util.regex.Pattern;
8 |
9 | import de.wirecard.accept.sdk.AcceptSDK;
10 |
11 | public class AdditionalPaymentFieldsActivity extends BaseActivity {
12 | private EditText functionId, jobId, descriptor, orderNumber;
13 | private TextInputLayout functionLayout, jobLayout, descriptorLayout, orderNumberLayout;
14 | private boolean validData = true;
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_additional_payment_fields);
20 | jobId = (EditText) findViewById(R.id.job_id);
21 | functionId = (EditText) findViewById(R.id.function_id);
22 | descriptor = (EditText) findViewById(R.id.descriptor);
23 | orderNumber = (EditText) findViewById(R.id.order_no);
24 | functionLayout = (TextInputLayout) findViewById(R.id.function_id_layout);
25 | jobLayout = (TextInputLayout) findViewById(R.id.job_id_layout);
26 | descriptorLayout = (TextInputLayout) findViewById(R.id.descriptor_layout);
27 | orderNumberLayout = (TextInputLayout) findViewById(R.id.order_no_layout);
28 | }
29 |
30 | public void saveInputs() {
31 |
32 | AcceptSDK.setJobId(jobId.getText().toString());
33 | AcceptSDK.setFunctionId(functionId.getText().toString());
34 | AcceptSDK.setDescriptor(descriptor.getText().toString());
35 | AcceptSDK.setOrderNumber(orderNumber.getText().toString());
36 | //setters may produce error when maximal length is exceeded or format is violated
37 | validData = AcceptSDK.validatePEandEEFields().isEmpty();
38 | }
39 |
40 | @Override
41 | public void onBackPressed() {
42 | saveInputs();
43 | if (validData) {
44 | super.onBackPressed();
45 | } else {
46 | showErrors();
47 | doubleBackToExit();
48 | }
49 | }
50 |
51 | private void cleanErrors() {
52 | functionLayout.setError(null);
53 | jobLayout.setError(null);
54 | orderNumberLayout.setError(null);
55 | descriptorLayout.setError(null);
56 | }
57 |
58 | private void showErrors() {
59 | cleanErrors();
60 | Pattern p = Pattern.compile("[^a-z0-9]", Pattern.CASE_INSENSITIVE);
61 | if (jobId.length() > 32) {
62 | jobLayout.setError("Job id can't be longer than 32 characters. ");
63 | }
64 | if (jobId.length() > 0 && p.matcher(jobId.getText()).find()) {
65 | jobLayout.setError(jobLayout.getError() != null ? jobLayout.getError() + "Job id must be alphanumeric." : "Job id must be alphanumeric.");
66 | }
67 | if (functionId.length() > 32) {
68 | functionLayout.setError("Function id can't be longer than 32 characters.");
69 | }
70 | if (functionId.length() > 0 && p.matcher(functionId.getText()).find()) {
71 | functionLayout.setError(functionLayout.getError() != null ? functionId.getError() + "Function id must be alphanumeric." : "Function id must be alphanumeric.");
72 | }
73 | if (descriptor.length() > 64) {
74 | descriptorLayout.setError("Descriptor can't be longer than 64 characters.");
75 | }
76 | if (orderNumber.length() > 64) {
77 | orderNumberLayout.setError("Order number can't be longer than 64 characters.");
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/demo/demo/sample/src/main/java/de/wirecard/accept/sample/AlipayPaymentActivity.java:
--------------------------------------------------------------------------------
1 | package de.wirecard.accept.sample;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 |
8 | import com.google.zxing.integration.android.IntentIntegrator;
9 | import com.google.zxing.integration.android.IntentResult;
10 |
11 | import de.wirecard.accept.sdk.AcceptSDK;
12 | import de.wirecard.accept.sdk.ApiResult;
13 | import de.wirecard.accept.sdk.OnRequestFinishedListener;
14 | import de.wirecard.accept.sdk.model.Payment;
15 | import de.wirecard.accept.sdk.util.CurrencyCode;
16 |
17 | public class AlipayPaymentActivity extends AbstractPaymentFlowActivity {
18 |
19 | public static Intent intent(final Context context) {
20 | return new Intent(context, AlipayPaymentActivity.class);
21 | }
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | showProgress(-1, false);
27 | AcceptSDK.setPaymentTransactionType(AcceptSDK.TransactionType.ALIPAY_PAYMENT);
28 |
29 | //normally its set by default from merchant config...in this case we will overwrite merchant setting because Alipay is supported only for USD
30 | AcceptSDK.setCurrency(CurrencyCode.USD.name());
31 |
32 | }
33 |
34 | @Override
35 | protected void onPayButtonClick() {
36 | IntentIntegrator integrator = new IntentIntegrator(this);
37 | //accepting all types of barcodes that application can read
38 | integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
39 | integrator.setPrompt("Scan a barcode");
40 | integrator.setCameraId(0); // Use a specific camera of the device
41 | integrator.setBeepEnabled(false);
42 | integrator.setBarcodeImageEnabled(true);
43 | integrator.initiateScan();
44 | }
45 |
46 | @Override
47 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
48 | IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
49 | if(result != null) {
50 | if(result.getContents() == null) {
51 | Log.d(TAG, "Cancelled barcode scan");
52 | showResultSection(false);
53 | } else {
54 | Log.d(TAG, "Scanned "+result.getContents());
55 | doAlipayPayment(result.getContents());
56 | }
57 | } else {
58 | // This is important, otherwise the result will not be passed to the fragment
59 | super.onActivityResult(requestCode, resultCode, data);
60 | }
61 | }
62 |
63 | private void doAlipayPayment(String customerCode){
64 | showProgress("Sending data...", true);
65 | AcceptSDK.setAlipayCustomerCode(customerCode);
66 | AcceptSDK.postAliPayPayment(new OnRequestFinishedListener() {
67 | @Override
68 | public void onRequestFinished(ApiResult apiResult, final Payment result) {
69 | showProgress(-1, false);
70 | if (apiResult.isSuccess()) {
71 | showResultSection(true);
72 | } else {
73 | showResultSection(false);
74 | }
75 | }
76 | });
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/demo/demo/sample/src/main/java/de/wirecard/accept/sample/Application.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015 Wirecard. All rights reserved.
3 | *
4 | * Accept SDK for Android
5 | *
6 | */
7 | package de.wirecard.accept.sample;
8 |
9 | import android.content.BroadcastReceiver;
10 | import android.content.Context;
11 | import android.content.Intent;
12 | import android.content.IntentFilter;
13 | import android.support.v4.content.LocalBroadcastManager;
14 | import android.util.Log;
15 |
16 | import java.util.HashMap;
17 |
18 | import de.wirecard.accept.sdk.AcceptSDK;
19 | import de.wirecard.accept.sdk.AcceptSDKIntents;
20 | import de.wirecard.accept.sdk.ApiResult;
21 | import de.wirecard.accept.sdk.OnRequestFinishedListener;
22 |
23 | public class Application extends android.app.Application {
24 |
25 | String errorMessage = "";
26 | SessionTerminatedReceiver receiver = null;
27 |
28 | protected Boolean usb = false;// used for switch using usb or bt
29 | protected Boolean contactless = false;// used for switch using usb or bt
30 |
31 | @Override
32 | public void onCreate() {
33 | super.onCreate();
34 | // Init loads the rest of configuration from config_for_accept.xml file.
35 |
36 | receiver = new SessionTerminatedReceiver();
37 |
38 | usb = getResources().getBoolean(R.bool.demo_communicate_with_spire_on_usb);
39 | contactless = getResources().getBoolean(R.bool.demo_support_contactless);
40 |
41 | try {
42 | AcceptSDK.init(this,
43 | BuildConfig.clientID, //Please obtain ClientID/Secret from Accept support team.
44 | BuildConfig.clientSecret, // demo app is using external file for fill this attributes
45 | BuildConfig.apiPath); //https://github.com/mposSVK/acceptSDK-Android/blob/master/demo/AcceptSDKAndroidDemo.properties
46 | AcceptSDK.loadExtensions(this, null, contactless, usb);
47 | } catch (IllegalArgumentException e) {
48 | errorMessage = e.getMessage();
49 | }
50 |
51 | AcceptSDK.setPrefTimeout(15);//timeout for requests
52 | if (AcceptSDK.isLoggedIn()) {
53 | //use this if you will stay on same session, just app is working on longer task
54 | AcceptSDK.sessionRefresh(new OnRequestFinishedListener>() {
55 | @Override
56 | public void onRequestFinished(ApiResult apiResult, HashMap result) {
57 | if (!apiResult.isSuccess()) {
58 | sendLogoutIntentAndGoLogin();
59 | }
60 | }
61 | });
62 | }
63 | //!!! do not forget on session terminated receiver
64 | // is importand to be able detect situation which should logout from payment service
65 | LocalBroadcastManager.getInstance(this).registerReceiver(receiver, new IntentFilter(AcceptSDKIntents.SESSION_TERMINATED));
66 | }
67 |
68 | public String getErrorMessage() {
69 | return errorMessage;
70 | }
71 |
72 | public void sendLogoutIntentAndGoLogin() {
73 | AcceptSDK.logout();
74 | Intent intent = new Intent(this, LoginActivity.class);
75 | intent.putExtra(BaseActivity.LOGOUT, true).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
76 | startActivity(intent);
77 |
78 | intent = new Intent(BaseActivity.INTENT);
79 | intent.putExtra(BaseActivity.INTENT_TYPE, BaseActivity.TYPE_LOGOUT);
80 | LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
81 | }
82 |
83 | private class SessionTerminatedReceiver extends BroadcastReceiver {
84 |
85 | @Override
86 | public void onReceive(Context context, Intent intent) {
87 | Log.e("Session Timeout", "sending Log Out");
88 | sendLogoutIntentAndGoLogin();
89 | }
90 | }
91 |
92 | @Override
93 | public void onTerminate() {
94 | LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
95 | AcceptSDK.finish();
96 | super.onTerminate();
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/demo/demo/sample/src/main/java/de/wirecard/accept/sample/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package de.wirecard.accept.sample;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.IntentFilter;
7 | import android.os.Bundle;
8 | import android.os.Handler;
9 | import android.support.v4.content.LocalBroadcastManager;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.util.Log;
12 | import android.widget.Toast;
13 |
14 | public class BaseActivity extends AppCompatActivity/*Activity*/ {
15 |
16 | final String TAG = BaseActivity.class.getSimpleName();
17 |
18 | public static final String LOGOUT = "logout";
19 | public final static String INTENT = "acceptsdk_intent";
20 | public final static String INTENT_TYPE = "acceptsdk_intent_type";
21 |
22 | public final static String SEPA = "sepa";
23 | public final static String CURRENT_DEVICE = "currentUsedDevice";
24 | public final static String CASH_BACK = "cashBack";
25 |
26 | public final static int TYPE_LOGOUT = 1;
27 | private boolean doubleBackToExitPressedOnce;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | Log.e(TAG, "onCreate");
33 | LocalBroadcastManager.getInstance(this).registerReceiver(mLogoutReceiver, new IntentFilter(INTENT));
34 | doubleBackToExitPressedOnce = false;
35 | }
36 |
37 | @Override
38 | protected void onDestroy() {
39 | super.onDestroy();
40 | LocalBroadcastManager.getInstance(this).unregisterReceiver(mLogoutReceiver);
41 | }
42 |
43 | /**
44 | * Receiver for "timeout" of server login session. After timeout You have to login again
45 | */
46 | private final BroadcastReceiver mLogoutReceiver = new BroadcastReceiver() {
47 | @Override
48 | public void onReceive(Context context, Intent intent) {
49 | Bundle extras = null;
50 | if (intent != null)
51 | extras = intent.getExtras();
52 | if (extras != null) {
53 | switch (extras.getInt(INTENT_TYPE)) {
54 | case TYPE_LOGOUT:
55 | // Kill receiving activity
56 | Log.e(TAG, ">>>>>>>>>>>>> LOGOUT <<<<<<<<<<<<<<<<");
57 | finish();
58 | break;
59 | default:
60 | break;
61 | }
62 | }
63 | }
64 | };
65 |
66 | protected void doubleBackToExit() {
67 | if (doubleBackToExitPressedOnce) {
68 | super.onBackPressed();
69 | return;
70 | }
71 |
72 | this.doubleBackToExitPressedOnce = true;
73 | Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show();
74 |
75 | new Handler().postDelayed(new Runnable() {
76 |
77 | @Override
78 | public void run() {
79 | doubleBackToExitPressedOnce = false;
80 | }
81 | }, 2000);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/demo/demo/sample/src/main/java/de/wirecard/accept/sample/CashPaymentActivity.java:
--------------------------------------------------------------------------------
1 | package de.wirecard.accept.sample;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 |
8 | import de.wirecard.accept.sdk.AcceptSDK;
9 | import de.wirecard.accept.sdk.ApiResult;
10 | import de.wirecard.accept.sdk.OnRequestFinishedListener;
11 | import de.wirecard.accept.sdk.model.Payment;
12 |
13 | public class CashPaymentActivity extends AbstractPaymentFlowActivity {
14 |
15 | public static Intent intent(Context applicationContext) {
16 | return new Intent(applicationContext, CashPaymentActivity.class);
17 | }
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | showProgress(-1, false);
23 | }
24 |
25 | @Override
26 | protected void onPayButtonClick() {
27 | showProgress("Sending data", true);
28 | AcceptSDK.setPaymentTransactionType(AcceptSDK.TransactionType.CASH_PAYMENT);
29 | AcceptSDK.postCashPayment(new OnRequestFinishedListener() {
30 | @Override
31 | public void onRequestFinished(ApiResult apiResult, Payment result) {
32 | if(apiResult.isSuccess()){
33 | showResultSection(true);
34 | showReceipt(result);
35 | } else {
36 | showResultSection(false);
37 | }
38 | }
39 | });
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/demo/demo/sample/src/main/java/de/wirecard/accept/sample/CurrencyUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015 Wirecard. All rights reserved.
3 | *
4 | * Accept SDK for Android
5 | *
6 | */
7 | package de.wirecard.accept.sample;
8 |
9 | import java.math.BigDecimal;
10 | import java.text.NumberFormat;
11 | import java.util.Currency;
12 | import java.util.Locale;
13 |
14 | public class CurrencyUtils {
15 |
16 | public static String format(long units, Currency currency, Locale locale) {
17 | final NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale);
18 | if (currency != null) {
19 | numberFormat.setCurrency(currency);
20 | return numberFormat.format(new BigDecimal(units).scaleByPowerOfTen(-currency.getDefaultFractionDigits()).doubleValue());
21 | } else {
22 | return numberFormat.format(units);
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/demo/demo/sample/src/main/java/de/wirecard/accept/sample/LoginActivity.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015 Wirecard. All rights reserved.
3 | *
4 | * Accept SDK for Android
5 | *
6 | */
7 | package de.wirecard.accept.sample;
8 |
9 | import android.app.Activity;
10 | import android.app.AlertDialog;
11 | import android.content.Intent;
12 | import android.content.SharedPreferences;
13 | import android.os.Bundle;
14 | import android.text.TextUtils;
15 | import android.view.View;
16 | import android.widget.EditText;
17 | import android.widget.TextView;
18 |
19 | import de.wirecard.accept.sdk.AcceptSDK;
20 | import de.wirecard.accept.sdk.ApiResult;
21 | import de.wirecard.accept.sdk.OnRequestFinishedListener;
22 |
23 |
24 |
25 | public class LoginActivity extends BaseActivity {
26 |
27 | private SharedPreferences sharedPreferences;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_login);
33 |
34 | String sdkWrongConfigErrorMessage = ((Application) getApplication()).getErrorMessage();
35 | if(!TextUtils.isEmpty(sdkWrongConfigErrorMessage)) {
36 | Intent i = new Intent(this, WrongAcceptSettingsActivity.class);
37 | i.putExtra("TEXT", sdkWrongConfigErrorMessage);
38 | startActivity(i);
39 | finish();
40 | return;
41 | }
42 | if ( !TextUtils.isEmpty(AcceptSDK.getToken()) ) {
43 | startActivity(MenuActivity.intent(this));
44 | finish();
45 | return;
46 | }
47 | findViewById(R.id.action).setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View v) {
50 | handleOnLoginPressed();
51 | }
52 | });
53 | ((TextView) findViewById(R.id.backend)).setText(BuildConfig.apiPath);
54 | ((TextView) findViewById(R.id.version)).setText("Version: " + BuildConfig.VERSION_NAME +"("+ BuildConfig.VERSION_CODE + ")");
55 |
56 | sharedPreferences = getSharedPreferences("demo", Activity.MODE_PRIVATE);
57 | if (sharedPreferences != null) {
58 | EditText usernameEditText = (EditText) findViewById(R.id.username);
59 | if (usernameEditText != null)
60 | usernameEditText.setText(getLastUsedUserName());
61 |
62 | EditText passwordEditText = (EditText) findViewById(R.id.password);
63 | if (passwordEditText != null)
64 | passwordEditText.setText(getLastUsedUserPass());
65 | }
66 | }
67 |
68 | @Override
69 | protected void onResume() {
70 | super.onResume();
71 | }
72 |
73 | private void handleOnLoginPressed() {
74 | final EditText usernameEditText = (EditText)findViewById(R.id.username);
75 | final EditText passwordEditText = (EditText)findViewById(R.id.password);
76 | final String username = usernameEditText.getText().toString();
77 | final String password = passwordEditText.getText().toString();
78 | if ( TextUtils.isEmpty(username) ) {
79 | presentFormError("Username field is empty.");
80 | return;
81 | }
82 | if ( TextUtils.isEmpty(password) ) {
83 | presentFormError("Password field is empty.");
84 | return;
85 | }
86 | enableForm(false);
87 |
88 | if (sharedPreferences != null)
89 | rememberLastUsedUser(username, password);
90 |
91 | AcceptSDK.login(username, password, new OnRequestFinishedListener