package com.example.androidstripepayments;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.parse.FunctionCallback;
import com.parse.ParseCloud;
import com.stripe.android.Stripe;
import com.stripe.android.TokenCallback;
import com.stripe.android.model.Card;
import com.stripe.android.model.Token;
import java.text.ParseException;
import java.util.HashMap;
//import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
public static final String PUBLISHABLE_KEY = "pk_test_qeSW2ZpZCFBZe0";
private Card card;
private ProgressDialog progress;
private Button purchase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
card = new Card(
"4242424242424242", //card number
12, //expMonth
2030,//expYear
"123"//cvc
);
progress = new ProgressDialog(this);
purchase = (Button) findViewById(R.id.purchase);
purchase.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buy();
}
});
}
private void buy(){
boolean validation = card.validateCard();
if(validation){
startProgress("Validating Credit Card");
new Stripe(this).createToken(
card,
PUBLISHABLE_KEY,
У меня возникли проблемы с этой строкой прямо здесь с TokenCallback (). И я не знаю, как заменить этот метод другим методом, чтобы он работал. Каждый раз, когда я компилирую код, я всегда получаю ту же ошибку. TokenCallback всегда выделено красным. Это также не позволяет мне использовать библиотеку. Эта библиотека, кажется, больше не работает по какой-либо причине.
new TokenCallback() {
@Override
public void onError(Exception error) {
Toast.makeText(MainActivity.this,
"Stripe -" + error.toString(),
Toast.LENGTH_LONG).show();
}
@Override
public void onSuccess(Token token) {
finishProgress();
charge(token);
}
});
} else if (!card.validateNumber()) {
Toast.makeText(MainActivity.this,
"Stripe - The card number that you entered is invalid",
Toast.LENGTH_LONG).show();
} else if (!card.validateExpiryDate()) {
Toast.makeText(MainActivity.this,
"Stripe - The expiration date that you entered is invalid",
Toast.LENGTH_LONG).show();
} else if (!card.validateCVC()) {
Toast.makeText(MainActivity.this,
"Stripe - The CVC code that you entered is invalid",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MainActivity.this,
"Stripe - The card details that you entered are invalid",
Toast.LENGTH_LONG).show();
}
}
private void charge(Token cardToken){
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("ItemName", "test");
params.put("cardToken", cardToken.getId());
params.put("name","Dominic Wong");
params.put("email","dominwong4@gmail.com");
params.put("address","HIHI");
params.put("zip","99999");
params.put("city_state","CA");
startProgress("Purchasing Item");
ParseCloud.callFunctionInBackground("purchaseItem", params, new FunctionCallback<Object>() {
public void done(Object response, ParseException e) {
finishProgress();
if (e == null) {
Log.d("Cloud Response", "There were no exceptions! " + response.toString());
Toast.makeText(getApplicationContext(),
"Item Purchased Successfully ",
Toast.LENGTH_LONG).show();
} else {
Log.d("Cloud Response", "Exception: " + e);
Toast.makeText(getApplicationContext(),
e.getMessage().toString(),
Toast.LENGTH_LONG).show();
}
}
});
}
private void startProgress(String title){
progress.setTitle(title);
progress.setMessage("Please Wait");
progress.show();
}
private void finishProgress(){
progress.dismiss();
}
}
это build.gradle (Project :) Я почти уверен, что добавил все нужные зависимости
// Top-level build file where you can add configuration options common to all sub- projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Это мой build.gradle (модуль), я обязательно добавил сюда все нужные вещи.
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.androidstripepayments"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
ext {
parseVersion = "1.23.1"
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.2.1'
implementation 'androidx.navigation:navigation-ui:2.2.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// Stripe Package
implementation 'com.stripe:stripe-android:+'
implementation "com.github.parse-community.Parse-SDK-Android:coroutines:1.23.1"
implementation 'com.parse.bolts:bolts-android:1.4.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.1'
implementation "com.github.parse-community.Parse-SDK-Android:parse:$parseVersion"
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}