0

I am trying to integrate Stripe payment gateway in android using their latest sdk and following their documentation.

I am using their card element ui and payment is working fine in test mode.

Here is the link to their documentation.

https://stripe.com/docs/payments/accept-a-payment?platform=android&ui=custom

The problem is, I am unable to get transaction details e.g Stripe_trx_id , Reciept_url etc...

here is my code which only tells completed and no other details.

// Stripe Android SDK
  implementation 'com.stripe:stripe-android:20.25.2'
import com.stripe.android.PaymentConfiguration;

public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        PaymentConfiguration.init(
            getApplicationContext(),
            "pk_test_qblFNYngBkEdjEZ16jxxoWSM"
        );
    }
}

Carde Element UI

<com.stripe.android.view.CardInputWidget
        android:id="@+id/cardInputWidget"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

Payment Intent on Server Side

// Set your secret key.
\Stripe\Stripe::setApiKey('sk_test_26PHem9AhJZvU623DfE1x4sd');

$intent = \Stripe\PaymentIntent::create([
  'amount' => 1099,
  'currency' => 'usd',
]);
$client_secret = $intent->client_secret;
// Pass the client secret to the client

public class CardActivity extends AppCompatActivity {
    // ...
    private String paymentIntentClientSecret;
    private PaymentLauncher paymentLauncher;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // ...

        final PaymentConfiguration paymentConfiguration
          = PaymentConfiguration.getInstance(getApplicationContext());
        paymentLauncher = PaymentLauncher.Companion.create(
            this,
            paymentConfiguration.getPublishableKey(),
            paymentConfiguration.getStripeAccountId(),
            this::onPaymentResult
        );
        startCheckout();
    }

    private void startCheckout() {
        // ...

        // Hook up the pay button to the card widget
        final Button payButton = findViewById(R.id.payButton);
        payButton.setOnClickListener((View view) -> {
            final CardInputWidget cardInputWidget = view.findViewById(R.id.cardInputWidget);
            final PaymentMethodCreateParams params = cardInputWidget.getPaymentMethodCreateParams();
            if (params != null) {
                final ConfirmPaymentIntentParams confirmParams =
                ConfirmPaymentIntentParams.createWithPaymentMethodCreateParams(
                  params,
                  paymentIntentClientSecret
                );
                paymentLauncher.confirm(confirmParams);
            }
        });
    }

    private void onPaymentResult(PaymentResult paymentResult) {
        String message = "";
        if (paymentResult instanceof PaymentResult.Completed) {
            message = "Completed!";
        } else if (paymentResult instanceof PaymentResult.Canceled) {
            message = "Canceled!";
        } else if (paymentResult instanceof PaymentResult.Failed) {
            // This string comes from the PaymentIntent's error message.
            // See here: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-last_payment_error-message
            message = "Failed: "
            + ((PaymentResult.Failed) paymentResult).getThrowable().getMessage();
        }

        displayAlert("PaymentResult: ", message, true);
    }
}

I want to get stripe transaction details once payment is completed...?

Addi.Star
  • 475
  • 2
  • 15
  • 36

1 Answers1

0

Most details you can find on the associated Payment Intent object. To get these details after the customer submits payment (to fulfill the order, etc), it's recommended you use Webhooks.

Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events also makes it easier to accept more payment methods in the future.

Check out this guide for more info.