问题描述
您好,亲爱的
首先,这不是问题。我只想分享一下我快要成为僵尸的经历。
我有一个销售商品的Android应用,我尝试添加“ PayTabs”付款,并且遇到了一些问题,例如当我结帐并购买了一些物品时,我没有收到来自“ onActivityResult /的回叫”成功。”或者,如果“交易成功”,则银行页面继续显示,并且“ onActivityResult”方法不起作用!我花了一个星期的时间来解决它。最后,我做到了。然后,我通过电子邮件联系了PayTabs支持部门。
https://dev.paytabs.com/docs/android/
第一步:
Intent in = new Intent(getApplicationContext(),Paytabactivity.class);
in.putExtra(PaymentParams.MERCHANT_EMAIL,"merchant-email@example.com"); //this a demo account for
testing the sdk
in.putExtra(PaymentParams.SECRET_KEY,"secret key");//Add your Secret Key Here
in.putExtra(PaymentParams.LANGUAGE,PaymentParams.ENGLISH);
in.putExtra(PaymentParams.TRANSACTION_TITLE,"Test Paytabs android library");
in.putExtra(PaymentParams.AMOUNT,5.0);
in.putExtra(PaymentParams.CURRENCY_CODE,"BHD"); // <<< this one
in.putExtra(PaymentParams.CUSTOMER_PHONE_NUMBER,"009733");
in.putExtra(PaymentParams.CUSTOMER_EMAIL,"customer-email@example.com");
in.putExtra(PaymentParams.ORDER_ID,"123456");
in.putExtra(PaymentParams.PRODUCT_NAME,"Product 1,Product 2");
//Billing Address
in.putExtra(PaymentParams.ADDRESS_BILLING,"Flat 1,Building 123,Road 2345");
in.putExtra(PaymentParams.CITY_BILLING,"Manama");
in.putExtra(PaymentParams.STATE_BILLING,"Manama");
in.putExtra(PaymentParams.COUNTRY_BILLING,"BHR"); // <<< the second one
in.putExtra(PaymentParams.POSTAL_CODE_BILLING,"00973"); //Put Country Phone code if Postal code not available '00973'
//Shipping Address
in.putExtra(PaymentParams.ADDRESS_SHIPPING,Road 2345");
in.putExtra(PaymentParams.CITY_SHIPPING,"Manama");
in.putExtra(PaymentParams.STATE_SHIPPING,"Manama");
in.putExtra(PaymentParams.COUNTRY_SHIPPING,"BHR"); // <<< and the third one
in.putExtra(PaymentParams.POSTAL_CODE_SHIPPING,"00973"); //Put Country Phone code if Postal code not available '00973'
//Payment Page Style
in.putExtra(PaymentParams.PAY_BUTTON_COLOR,"#2474bc");
//Tokenization
in.putExtra(PaymentParams.IS_TOKENIZATION,true); // <<< and the fourth one
startActivityForResult(in,PaymentParams.PAYMENT_REQUEST_CODE);
in.putExtra(PaymentParams.CURRENCY_CODE,*"BHD"*); // <<< this one
in.putExtra(PaymentParams.COUNTRY_BILLING,*"BHR"*); // <<< the second one
in.putExtra(PaymentParams.COUNTRY_SHIPPING,*"BHR"*); // <<< and the third one
通过Wikipedia输入正确的ISO 3166国家/地区代码。
in.putExtra(PaymentParams.IS_TOKENIZATION,true); // <<< and the fourth one
in.putExtra(PaymentParams.IS_TOKENIZATION,true); // <<< and the fourth one
,并且如Paytabs支持所说:“请确保您未在请求中传递预授权或令牌化。” 我删除了它们。
第二步:
我替换了这段代码。
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data) {
super.onActivityResult(requestCode,resultCode,data);
if (resultCode == RESULT_OK && requestCode == PaymentParams.PAYMENT_REQUEST_CODE) {
Log.e("Tag",data.getStringExtra(PaymentParams.RESPONSE_CODE));
Log.e("Tag",data.getStringExtra(PaymentParams.TRANSACTION_ID));
if (data.hasExtra(PaymentParams.TOKEN) && !data.getStringExtra(PaymentParams.TOKEN).isEmpty()) {
Log.e("Tag",data.getStringExtra(PaymentParams.TOKEN));
Log.e("Tag",data.getStringExtra(PaymentParams.CUSTOMER_EMAIL));
Log.e("Tag",data.getStringExtra(PaymentParams.CUSTOMER_PASSWORD));
}
}
}
要这样
btn.setonClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
PayNow();
}
} );
// =========
private void PayNow() {
Intent in = new Intent(getApplicationContext(),Paytabactivity.class);
in.putExtra(PaymentParams.MERCHANT_EMAIL,"merchant-email@example.com"); //this a demo account for
testing the sdk
in.putExtra(PaymentParams.SECRET_KEY,"secret key");//Add your Secret Key Here
in.putExtra(PaymentParams.LANGUAGE,PaymentParams.ENGLISH);
in.putExtra(PaymentParams.TRANSACTION_TITLE,"Test Paytabs android library");
in.putExtra(PaymentParams.AMOUNT,5.0);
in.putExtra(PaymentParams.CURRENCY_CODE,"");
in.putExtra(PaymentParams.CUSTOMER_PHONE_NUMBER,"009733");
in.putExtra(PaymentParams.CUSTOMER_EMAIL,"customer-email@example.com");
in.putExtra(PaymentParams.ORDER_ID,"123456");
in.putExtra(PaymentParams.PRODUCT_NAME,Product 2");
//Billing Address
in.putExtra(PaymentParams.ADDRESS_BILLING,Road 2345");
in.putExtra(PaymentParams.CITY_BILLING,"");
in.putExtra(PaymentParams.STATE_BILLING,"");
in.putExtra(PaymentParams.COUNTRY_BILLING,"");
in.putExtra(PaymentParams.POSTAL_CODE_BILLING,""); //Put Country Phone code if Postal code not available '00973'
//Shipping Address
in.putExtra(PaymentParams.ADDRESS_SHIPPING,Road 2345");
in.putExtra(PaymentParams.CITY_SHIPPING,"");
in.putExtra(PaymentParams.STATE_SHIPPING,"");
in.putExtra(PaymentParams.COUNTRY_SHIPPING,"");
in.putExtra(PaymentParams.POSTAL_CODE_SHIPPING,""); //Put Country Phone code if Postal code not available '00973'
//Payment Page Style
in.putExtra(PaymentParams.PAY_BUTTON_COLOR,"#2474bc");
//Tokenization
//in.putExtra(PaymentParams.IS_TOKENIZATION,true); // remove this!
//startActivityForResult(in,PaymentParams.PAYMENT_REQUEST_CODE); // remove this!
mStartForResult.launch(in); // *add this! To get REQUEST_CODE and RESPONSE_CODE*
}
ActivityResultLauncher<Intent> mStartForResult = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),result -> {
if (result.getResultCode() == Activity.RESULT_OK && 1000 == PaymentParams.PAYMENT_REQUEST_CODE) {
Intent data = result.getData();
System.out.println( "getResultCode:: "+ result.getResultCode());
try {
Log.e( "Tag",Objects.requireNonNull( Objects.requireNonNull( data ).getStringExtra( PaymentParams.RESPONSE_CODE ) ) );
Log.e( "Tag",Objects.requireNonNull( Objects.requireNonNull( data ).getStringExtra( PaymentParams.TRANSACTION_ID ) ) );
System.out.println( "RESULT_OK:: "+ RESULT_OK);
System.out.println( "PAYMENT_REQUEST_CODE:: "+ PaymentParams.PAYMENT_REQUEST_CODE);
System.out.println( "RESPONSE_CODE:: "+ Objects.requireNonNull( data.getStringExtra( PaymentParams.RESPONSE_CODE ) ));
System.out.println( "TRANSACTION_ID:: "+ Objects.requireNonNull( data.getStringExtra( PaymentParams.TRANSACTION_ID ) ));
System.out.println( "RESULT_MESSAGE:: "+ Objects.requireNonNull( data.getStringExtra( PaymentParams.RESULT_MESSAGE ) ));
if( Objects.requireNonNull( data.getStringExtra( PaymentParams.RESPONSE_CODE ) ).matches( 100+"" ) ){
// do your Magical code
}else if( !Objects.requireNonNull( data.getStringExtra( PaymentParams.RESPONSE_CODE ) ).matches( 100+"" ) ){
Toast.makeText( this,"Card is Error:: " + PaymentParams.PAYMENT_REQUEST_CODE + " ::",Toast.LENGTH_SHORT ).show();
System.out.println( TAG + ":: Error:: " + PaymentParams.PAYMENT_REQUEST_CODE );
}
if (data.hasExtra( PaymentParams.TOKEN )
&& !Objects.requireNonNull( data.getStringExtra( PaymentParams.TOKEN ) ).isEmpty()) {
Log.e( "Tag",Objects.requireNonNull( data.getStringExtra( PaymentParams.TOKEN ) ) );
Log.e( "Tag",Objects.requireNonNull( data.getStringExtra( PaymentParams.CUSTOMER_EMAIL ) ) );
Log.e( "Tag",Objects.requireNonNull( data.getStringExtra( PaymentParams.CUSTOMER_PASSWORD ) ) );
System.out.println( TAG + ":: TOKEN:: "+ Objects.requireNonNull( data.getStringExtra( PaymentParams.TOKEN ) ));
System.out.println( TAG + ":: CUSTOMER_EMAIL:: "+ Objects.requireNonNull( data.getStringExtra( PaymentParams.CUSTOMER_EMAIL ) ));
System.out.println( TAG + ":: CUSTOMER_PASSWORD:: "+ Objects.requireNonNull( data.getStringExtra( PaymentParams.CUSTOMER_PASSWORD ) ));
System.out.println( TAG + ":: RESULT_MESSAGE:: "+ Objects.requireNonNull( data.getStringExtra( PaymentParams.RESULT_MESSAGE ) ));
}
} catch (IllegalStateException e){
System.out.println( TAG + ":: IllegalStateException:: " + e );
System.out.println( TAG + ":: PAYMENT_REQUEST_CODE:: "+ PaymentParams.PAYMENT_REQUEST_CODE);
System.out.println( TAG + ":: RESPONSE_CODE:: "+ Objects.requireNonNull( Objects.requireNonNull( data ).getStringExtra( PaymentParams.RESPONSE_CODE ) ));
System.out.println( TAG + ":: RESULT_MESSAGE:: "+ Objects.requireNonNull( Objects.requireNonNull( data ).getStringExtra( PaymentParams.RESULT_MESSAGE ) ));
}
}else if ( result.getResultCode() == Activity.RESULT_CANCELED) {
Toast.makeText( this,"cancelled!",Toast.LENGTH_SHORT ).show();
}
} );
**我希望它对您有用。
欢呼**
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)