我试图在Android中集成条纹支付网关使用他们最新的SDK和以下他们的文档.
我正在使用他们的卡元素用户界面和支付工作正常,在测试模式。
这里是他们文档的链接。
https://stripe.com/docs/payments/accept-a-payment?platform=android&ui=custom
问题是,我无法获取交易细节,例如Stripe_trx_id,Reciept_url等。
这是我的代码,它只告诉完成,没有其他细节。
// 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"
);
}
}
卡片ElementUI
<com.stripe.android.view.CardInputWidget
android:id="@+id/cardInputWidget"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
服务器端支付意向
// 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);
}
}
我想在付款完成后获得条带交易详细信息...?
1条答案
按热度按时间cetgtptt1#
您可以在相关的Payment Intent object上找到大部分详细信息。要在客户提交付款后获得这些详细信息(以完成订单等),建议您使用Webhooks。
侦听这些事件,而不是等待来自客户端的回调。在客户端上,客户可以在回调执行之前关闭浏览器窗口或退出应用程序,恶意客户端可以操纵响应。将集成设置为侦听异步事件还可以使将来更容易接受更多的支付方式。
查看this guide了解更多信息。