Stripe Connect

@thiagolocatelli

View project onGitHub

android-stripe-connect

Android Library for integrating with Stripe using Stripe Connect Oauth.

Stripe ConnectStripe ConnectStripe Connect

Usage

You can add the Stripe Connect button to your layout using the following XML code:

    <com.github.thiagolocatelli.stripe.StripeButton
        android:id="@+id/btnStripeConnect"
        android:layout_height="wrap_content"
        android:layout_width="200dip" 
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dip"/>

You can create an utility class where you can define your application credentials, like the one below (This is obvilously insecure, make sure you keep all this information stored in a way its impossible to decompile):

public class ApplicationData {
    public static final String CLIENT_ID = "";
    public static final String CLIENT_SECRET = "";
    public static final String CALLBACK_URL = "";
}

Inside your Activity, you can manipulate the button and change its properties. You can either launch a Dialog to start the authentication or start a Activity. By default, the scope is read_only, if you want to give write permissions, you gotta use StripeApp object and pass "read_write" as scope.

StripeAppmApp = new StripeApp(this, ApplicationData.CLIENT_ID, 
                ApplicationData.SECRET_KEY, ApplicationData.CALLBACK_URL);

mStripeButton = (StripeButton) findViewById(R.id.btnStripeConnect);
        mStripeButton.setStripeApp(mApp);
        mStripeButton.addStripeConnectListener(new StripeConnectListener() {

            @Override
            public void onConnected() {
                tvSummary.setText("Connected as " + mApp.getAccessToken());
            }

            @Override
            public void onDisconnected() {
                tvSummary.setText("Disconnected");
            }

            @Override
            public void onError(String error) {
                Toast.makeText(MainActivity.this, error, Toast.LENGTH_SHORT).show();
            }

        });

By default, when the Stripe Connect button is clicked, an Android Dialog will open and display the Stripe authentication page. If you would like to open an Activity instead of a Dialog, you can use setConnectMode to change such behavior.

mStripeButton = (StripeButton) findViewById(R.id.btnStripeConnect);
mStripeButton.setStripeApp(mApp);
mStripeButton.setConnectMode(CONNECT_MODE.ACTIVITY);

You also need to add to your AndroidManifest.xml the following line, which will allow the Stripe Connect button to start the authentication Activity.

<activity android:name="com.github.thiagolocatelli.stripe.StripeActivity"  />

Once the authentication is finished, you can use the helper methods from the object StripeApp to get the data you need, like the oauth access token required to make calls using the Stripe Java library.

Stripe.apiKey = mApp.getAccessToken();

Download the sample application and git it a try.

Contact

If you have any questions, please drop me a line: "thiago:locatelli$gmail:com".replace(':','.').replace('$','@')