Search in sources :

Example 1 with BluetoothPaymentDeviceConnector

use of com.fitpay.android.paymentdevice.impl.ble.BluetoothPaymentDeviceConnector in project fitpay-android-sdk by fitpay.

the class DeviceService method configure.

protected void configure(Intent intent) {
    if (null == intent) {
        FPLog.e(TAG, "DeviceService can not be configured with a null Intent.  Current connector: " + paymentDeviceConnector);
        return;
    }
    if (null != intent.getExtras() && intent.hasExtra(EXTRA_PAYMENT_SERVICE_TYPE)) {
        paymentDeviceConnectorType = intent.getExtras().getString(EXTRA_PAYMENT_SERVICE_TYPE);
        if (null != paymentDeviceConnectorType) {
            switch(paymentDeviceConnectorType) {
                case PAYMENT_SERVICE_TYPE_MOCK:
                    {
                        paymentDeviceConnector = new MockPaymentDeviceConnector();
                        break;
                    }
                case PAYMENT_SERVICE_TYPE_FITPAY_BLE:
                    {
                        String bluetoothAddress = intent.getExtras().getString(BluetoothPaymentDeviceConnector.EXTRA_BLUETOOTH_ADDRESS);
                        paymentDeviceConnector = new BluetoothPaymentDeviceConnector(this, bluetoothAddress);
                        break;
                    }
                default:
                    {
                        FPLog.w(TAG, "payment service type is not one of the known types.  type: " + paymentDeviceConnectorType);
                    }
            }
            if (null == paymentDeviceConnector) {
                try {
                    Class paymentDeviceConnectorClass = forName(paymentDeviceConnectorType);
                    paymentDeviceConnector = (IPaymentDeviceConnector) paymentDeviceConnectorClass.newInstance();
                    paymentDeviceConnector.setContext(this);
                } catch (Exception e) {
                    FPLog.e(TAG, e);
                }
            }
        }
    }
    if (null != paymentDeviceConnector && intent.hasExtra(EXTRA_PAYMENT_SERVICE_CONFIG)) {
        configParams = intent.getExtras().getString(EXTRA_PAYMENT_SERVICE_CONFIG);
        Properties props = null;
        try {
            props = convertCommaSeparatedList(configParams);
        } catch (IOException e) {
            FPLog.e(TAG, "unable to load properties. Reason: " + e.getMessage());
        }
        if (null != props) {
            paymentDeviceConnector.init(props);
        }
    }
    if (null != paymentDeviceConnector) {
        paymentDeviceConnector.reset();
    }
}
Also used : BluetoothPaymentDeviceConnector(com.fitpay.android.paymentdevice.impl.ble.BluetoothPaymentDeviceConnector) MockPaymentDeviceConnector(com.fitpay.android.paymentdevice.impl.mock.MockPaymentDeviceConnector) IOException(java.io.IOException) Properties(java.util.Properties) IOException(java.io.IOException)

Aggregations

BluetoothPaymentDeviceConnector (com.fitpay.android.paymentdevice.impl.ble.BluetoothPaymentDeviceConnector)1 MockPaymentDeviceConnector (com.fitpay.android.paymentdevice.impl.mock.MockPaymentDeviceConnector)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1