Я перешел по этой ссылке https://stripe.com/docs/payments/accept-a-payment#android После выполнения всех шагов, когда у меня возникла ошибка тестирования, такого платежного намерения нет. Я получаю ключ клиента и publi sh с моего сервера. Когда я подтверждаю платеж , В диалоговом окне не отображается такое намерение платежа (секретный ключ клиента), метод getkey - получить publi sh и клиентский ключ с сервера,
public class CheckoutActivity extends AppCompatActivity implements View.OnClickListener {
Users user;
String ticket_id,price,paymentIntentClientSecret;
private Stripe stripe;
CardInputWidget cardInputWidget;
Button pay;
String stripePublishableKey;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_checkout);
user= SharedPrefManager.getInstance(this).getUser();
ticket_id=getIntent().getStringExtra("Ticket_Id");
price=getIntent().getStringExtra("Price");
cardInputWidget=findViewById(R.id.cardInputWidget);
pay=findViewById(R.id.payButton);
pay.setOnClickListener(this);
}
private boolean haveNetworkConnection() {
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) {
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
haveConnectedMobile = true;
}
return haveConnectedWifi || haveConnectedMobile;
}
public void getKey()
{
if(haveNetworkConnection())
{
Request stringRequest = new StringRequest(Request.Method.POST, Urls.PAYMENT_KEY, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("GET_KEY_RESPONSE",response);
try {
JSONObject object=new JSONObject(response);
if(object.optBoolean("success"))
{
// Toast.makeText(CheckoutActivity.this,object.optString("message"),Toast.LENGTH_SHORT).show();
paymentIntentClientSecret=object.optJSONObject("data").optString("client_secret");
stripePublishableKey=object.optJSONObject("data").optString("publish_key");
Log.d("key",paymentIntentClientSecret);
startCheckout();
}
else if(!object.optBoolean("success"))
{
Toast.makeText(CheckoutActivity.this,object.optString("message"),Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "get key for stripe error", Toast.LENGTH_SHORT).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("ticket_id", ticket_id);
params.put("amount", price);
params.put("currency", "usd");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Authorization",user.getToken());
return params;
}
};
RequestQueue requestQueue= Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
else if(!haveNetworkConnection())
{
Toast.makeText(this,"No Internet Connection Available!!!",Toast.LENGTH_SHORT).show();
}
}
@Override
public void onClick(View view) {
if(view == pay)
{
getKey();
}
}
public void startCheckout() {
PaymentMethodCreateParams params = cardInputWidget.getPaymentMethodCreateParams();
if (params != null) {
ConfirmPaymentIntentParams confirmParams = ConfirmPaymentIntentParams
.createWithPaymentMethodCreateParams(params, paymentIntentClientSecret);
final Context context = getApplicationContext();
stripe = new Stripe(
context,
Objects.requireNonNull(stripePublishableKey)
);
stripe.confirmPayment(this, confirmParams);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Handle the result of stripe.confirmPayment
stripe.onPaymentResult(requestCode, data, new PaymentResultCallback(this));
}
// ...
private static final class PaymentResultCallback
implements ApiResultCallback<PaymentIntentResult> {
@NonNull private final WeakReference<CheckoutActivity> activityRef;
PaymentResultCallback(@NonNull CheckoutActivity activity) {
activityRef = new WeakReference<>(activity);
}
@Override
public void onSuccess(@NonNull PaymentIntentResult result) {
final CheckoutActivity activity = activityRef.get();
if (activity == null) {
return;
}
PaymentIntent paymentIntent = result.getIntent();
PaymentIntent.Status status = paymentIntent.getStatus();
if (status == PaymentIntent.Status.Succeeded) {
// Payment completed successfully
Gson gson = new GsonBuilder().setPrettyPrinting().create();
activity.displayAlert(
"Payment completed",
gson.toJson(paymentIntent)
);
} else if (status == PaymentIntent.Status.RequiresPaymentMethod) {
// Payment failed
activity.displayAlert(
"Payment failed",
Objects.requireNonNull(paymentIntent.getLastPaymentError()).getMessage()
);
}
}
@Override
public void onError(@NonNull Exception e) {
final CheckoutActivity activity = activityRef.get();
if (activity == null) {
return;
}
// Payment request failed – allow retrying using the same payment method
activity.displayAlert("Error", e.toString());
}
}
private void displayAlert(@NonNull String title,
@Nullable String message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(title)
.setMessage(message);
builder.setPositiveButton("Ok", null);
builder.create().show();
}