私はアンドロイドペイストでストライプを使用して決済ゲートウェイを作成するには?
Card card=new Card(cardno,expmon,expyer,cvv);
card.validateNumber();
card.validateCVC();
new Stripe().createToken(card,PUBLISHABLE_KEY,
new TokenCallback() {
public void onSuccess(Token token) {
// Send token to your own web service
}
public void onError(Exception error) {
Toast.makeText(MainActivity.this, error.getLocalizedMessage(),
Toast.LENGTH_LONG).show();
}
}
);
、作成および検証するカードの詳細を、次のコードを使用してトークンを取得するために、独自のクレジットカードフォームを構築し使用してトークンを取得することができるが、私はあなたにアクセスするには、Androidペイを使用する方法がわかりませんストライプを使用してAndroidの有料顧客の保存されたカード情報は、私は次のコードを使用していますが、私はトークン
Class Androidpay extends FragmentActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
// You will need to use your live API key even while testing
public static final String PUBLISHABLE_KEY = "pk_test_zbtcr8iFQrLNU3zu1";
// Unique identifiers for asynchronous requests:
private static final int LOAD_MASKED_WALLET_REQUEST_CODE = 1000;
private static final int LOAD_FULL_WALLET_REQUEST_CODE = 1001;
private GoogleApiClient googleApiClient;
private SupportWalletFragment walletFragment;
public static final int mEnvironment = WalletConstants.ENVIRONMENT_TEST;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.androidpay);
googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Wallet.API, new Wallet.WalletOptions.Builder()
.setEnvironment(WalletConstants.ENVIRONMENT_TEST)
.setTheme(WalletConstants.THEME_LIGHT)
.build())
.build();
Wallet.Payments.isReadyToPay(googleApiClient).setResultCallback(
new ResultCallback<BooleanResult>() {
@Override
public void onResult(@NonNull BooleanResult booleanResult) {
if (booleanResult.getStatus().isSuccess()) {
if (booleanResult.getValue()) {
showAndroidPay();
} else {
// Hide Android Pay buttons, show a message that Android Pay
// cannot be used yet, and display a traditional checkout button
}
} else {
// Error making isReadyToPay call
// Log.e(TAG, "isReadyToPay:" + booleanResult.getStatus());
}
}
});
}
public void showAndroidPay()
{
setContentView(R.layout.activity_main);
walletFragment =
(SupportWalletFragment) getSupportFragmentManager().findFragmentById(R.id.wallet_fragment);
MaskedWalletRequest maskedWalletRequest = MaskedWalletRequest.newBuilder()
// Request credit card tokenization with Stripe by specifying tokenization parameters:
.setPaymentMethodTokenizationParameters(PaymentMethodTokenizationParameters.newBuilder()
.setPaymentMethodTokenizationType(PaymentMethodTokenizationType.PAYMENT_GATEWAY)
.addParameter("gateway", "stripe")
.addParameter("stripe:publishableKey", PUBLISHABLE_KEY)
.addParameter("stripe:version", com.stripe.Stripe.VERSION)
.build())
// You want the shipping address:
.setShippingAddressRequired(true)
// Price set as a decimal:
.setEstimatedTotalPrice("20.00")
.setCurrencyCode("USD")
.build();
// Set the parameters:
WalletFragmentInitParams initParams = WalletFragmentInitParams.newBuilder()
.setMaskedWalletRequest(maskedWalletRequest)
.setMaskedWalletRequestCode(LOAD_MASKED_WALLET_REQUEST_CODE)
.build();
// Initialize the fragment:
walletFragment.initialize(initParams);
}
public void onStart() {
super.onStart();
googleApiClient.connect();
}
public void onStop() {
super.onStop();
googleApiClient.disconnect();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == LOAD_MASKED_WALLET_REQUEST_CODE) { // Unique, identifying constant
if (resultCode == Activity.RESULT_OK) {
MaskedWallet maskedWallet = data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET);
FullWalletRequest fullWalletRequest = FullWalletRequest.newBuilder()
.setCart(Cart.newBuilder()
.setCurrencyCode("USD")
.setTotalPrice("20.00")
.addLineItem(LineItem.newBuilder() // Identify item being purchased
.setCurrencyCode("USD")
.setQuantity("1")
.setDescription("Premium Llama Food")
.setTotalPrice("20.00")
.setUnitPrice("20.00")
.build())
.build())
.setGoogleTransactionId(maskedWallet.getGoogleTransactionId())
.build();
Wallet.Payments.loadFullWallet(googleApiClient, fullWalletRequest, LOAD_FULL_WALLET_REQUEST_CODE);
}
} else if (requestCode == LOAD_FULL_WALLET_REQUEST_CODE)
{
if (resultCode == Activity.RESULT_OK) {
FullWallet fullWallet = data.getParcelableExtra(WalletConstants.EXTRA_FULL_WALLET);
String tokenJSON = fullWallet.getPaymentMethodToken().getToken();
//A token will only be returned in production mode,
//i.e. WalletConstants.ENVIRONMENT_PRODUCTION
if (mEnvironment == WalletConstants.ENVIRONMENT_PRODUCTION)
{
com.stripe.model.Token token = com.stripe.model.Token.GSON.fromJson(
tokenJSON, com.stripe.model.Token.class);
// TODO: send token to your server
Toast.makeText(Androidpay.this,"ready to send token"+token.getId()+token.getAmount(),Toast.LENGTH_SHORT).show();
}
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {}
@Override
public void onConnected(Bundle bundle) {}
@Override
public void onConnectionSuspended(int i) {}
}
解決方法はありましたか?私は同じコードを使用していますが、次の条件でコントロールを取得しました // Androidペイボタンを非表示、Android Pay //は使用できないというメッセージを表示し、従来のチェックアウトボタンを表示します –