Skip to content

Commit

Permalink
[1] Payment Intents Example Integration (#606)
Browse files Browse the repository at this point in the history
* pi demo

* address comments
  • Loading branch information
ksun2-stripe authored Jul 12, 2018
1 parent c349a5d commit 4be93ee
Show file tree
Hide file tree
Showing 8 changed files with 377 additions and 14 deletions.
14 changes: 14 additions & 0 deletions example/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@
<action android:name="android.intent.action.VIEW"/>
</intent-filter>
</activity>
<activity
android:name=".activity.PaymentIntentActivity"
android:theme="@style/SampleTheme"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>

<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>

<data
android:host="payment_intent_return"
android:scheme="stripe"/>
</intent-filter>
</activity>
<service
android:name=".service.TokenIntentService"
android:exported="false"/>
Expand Down
9 changes: 9 additions & 0 deletions example/res/layout/activity_launcher.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
android:text="@string/selectSampleActivity"
/>

<Button
android:id="@+id/btn_payment_intent"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="@string/launch_payment_intent_example"
/>

<Button
android:id="@+id/btn_make_card_tokens"
android:layout_width="200dp"
Expand Down
71 changes: 71 additions & 0 deletions example/res/layout/activity_payment_intent_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:stripe="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_margin="10dp"
>

<TextView
android:id="@+id/create_payment_intent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/create_payment_intent_backend"
/>

<Button
android:id="@+id/btn_create_payment_intent"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/create_payment_intent"
/>

<TextView
android:id="@+id/confirm_payment_intent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/create_source_and_confirm_payment_intent"
/>

<com.stripe.android.view.CardInputWidget
android:id="@+id/card_input_widget"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
stripe:cardHintText="@string/sample_card_requiring_3ds"
/>

<Button
android:id="@+id/btn_confirm_payment_intent"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:enabled="false"
android:text="@string/confirm_payment_intent"
/>

<Button
android:id="@+id/btn_retrieve_payment_intent"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:enabled="false"
android:text="@string/retrieve_payment_intent"
/>

<TextView
android:id="@+id/payment_intent_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

</LinearLayout>
</ScrollView>
12 changes: 11 additions & 1 deletion example/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
<string name="payment_session_select_shipping">Set Shipping Information</string>
<string name="payment_session_data">Payment Session Data</string>
<string name="startPaymentFlow">Start Payment Flow</string>

<string name="load_items">Load Items</string>
<string name="ok">OK</string>

Expand All @@ -61,4 +60,15 @@
<item>Unspecified</item>
<item>USD</item>
</string-array>

<string name="launch_payment_intent_example">Launch Payment Intent Example</string>
<string name="creating_payment_intent">Creating payment intent&#8230;</string>
<string name="confirming_payment_intent">Confirming payment intent&#8230;</string>
<string name="retrieving_payment_intent">Retrieving payment intent&#8230;</string>
<string name="create_payment_intent_backend">First, create a payment intent on your backend.</string>
<string name="create_payment_intent">Create payment intent</string>
<string name="create_source_and_confirm_payment_intent">Second, create a source and confirm the payment intent</string>
<string name="confirm_payment_intent">Confirm payment intent</string>
<string name="retrieve_payment_intent">Retrieve payment intent</string>
<string name="error_while_retrieving_payment_intent">An error occured while retrieving the payment intent</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_launcher);

PaymentConfiguration.init(PUBLISHABLE_KEY);

Button paymentIntentButton = findViewById(R.id.btn_payment_intent);
paymentIntentButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(LauncherActivity.this, PaymentIntentActivity.class);
startActivity(intent);
}
});
Button tokenButton = findViewById(R.id.btn_make_card_tokens);
tokenButton.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -78,6 +87,7 @@ public void onClick(View v) {
startActivity(intent);
}
});

}

}
Loading

0 comments on commit 4be93ee

Please sign in to comment.