我想在我的应用中集成付款,我使用了" FORT" SDK。我确实按照" payfort.com"网站,但当我集成库我的应用程序崩溃。
这是错误输出:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.newsolution.jiibli, PID: 12133
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.newsolution.jiibli/com.payfort.fort.android.sdk.activities.InitSecureConnectionActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7223)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:343)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:277)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.payfort.fort.android.sdk.activities.InitSecureConnectionActivity.onCreate(InitSecureConnectionActivity.java:50)
at android.app.Activity.performCreate(Activity.java:6877)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7223)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
答案 0 :(得分:0)
:我从AppCompactTheme
扩展了样式 <activity android:name=".Activity.PaymentMethod"
android:theme="@style/AppTheme"/>
在gradle中导入库
compile project(':FORTSDKv1.2')
我以意图结果启动PaymentMethod活动:
调用方法pay();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activity = this;
setContentView(R.layout.activity_payment_method);
fortCallback = FortCallback.Factory.create();
pay();
}
public void pay() {
try {
ProviderInstaller.installIfNeeded(getApplicationContext());
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
new sdkToken().execute();// get SDK Token and pass it to paid method
}
class sdkToken extends AsyncTask<String, Void, String> {
public sdkToken() {
}
protected void onPreExecute() {
super.onPreExecute();
}
protected String doInBackground(String... params) {
signature = getSignature();
String jsonRequestString = "{\"access_code\" : \""+access_code+"\" " +
", \"service_command\" : \"SDK_TOKEN\", \"language\" : \"en\","
+ "\"merchant_identifier\" : \""+merchant_identifier+"\", \"signature\" : \"" + signature + "\", "
+ "\"device_id\" : \"" + FortSdk.getDeviceId(PaymentMethod.this) + "\"}";
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
int timeoutConnection = 10000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 10000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
// Instantiate the custom HttpClient
HttpClient httpclient = new MyHttpClient(httpParameters, getApplicationContext());
// DefaultHttpClient httpclient =new DefaultHttpClient();
HttpPost request = new HttpPost("https://sbpaymentservices.payfort.com/FortAPI/paymentApi");
StringEntity param = null;
try {
param = new StringEntity(jsonRequestString);// Setup Http POST entity with JSON String
// Setup request type as JSON
request.addHeader("content-type", "application/json");
request.setEntity(param);
HttpResponse response = null;
response = httpclient.execute(request); // Post request to FORT
sb = new StringBuilder(); // Read response using StringBuilder
BufferedReader reader = null;
reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()), 65728);
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
return "" + sb.toString();
}
protected void onPostExecute(String fortResponse) {
super.onPostExecute(fortResponse);
if (fortResponse != null) {
JSONObject jsonObject = null;
System.out.println(sb.toString());
try {
jsonObject = new JSONObject(fortResponse);
sdk_token = jsonObject.getString("sdk_token");
System.out.println(sdk_token);
progressBar.setVisibility(View.GONE);
paid(sdk_token);
} catch (JSONException e) {
e.printStackTrace();
}
} else {
progressBar.setVisibility(View.GONE);
Log.i("fortResponse", " fortResponse==null");
Toast.makeText(activity, getString(R.string.compatible), Toast.LENGTH_LONG).show();
}
}
}
private void paid(String sdk_token) {
fortRequest = new FortRequest();
Map<String, String> requestMap = new HashMap<>();
requestMap.put("merchant_reference", random());
requestMap.put("language", "en");
requestMap.put("order_description", "android");
requestMap.put("currency", "SAR");
requestMap.put("amount", "100");
requestMap.put("command", "AUTHORIZATION");//PURCHASE
requestMap.put("customer_name", "add any name");
requestMap.put("eci", "ECOMMERCE");
requestMap.put("customer_email", "add email");
requestMap.put("sdk_token", sdk_token);
fortRequest.setShowResponsePage(true);
fortRequest.setRequestMap(requestMap);
try {
FortSdk.getInstance().registerCallback(this, fortRequest, FortSdk.ENVIRONMENT.TEST, 5, fortCallback,
new FortInterfaces.OnTnxProcessed() {
@Override
public void onCancel(Map<String, String> requestParamsMap, Map<String,
String> responseMap) {
//TODO: handle me
JSONObject responseObject = new JSONObject(responseMap);
try {
String response_message = responseObject.getString("response_message");
paymentType = 0;
Toast.makeText(PaymentMethod.this, "" + response_message, Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onSuccess(Map<String, String> requestParamsMap, Map<String,
String> fortResponseMap) {
System.out.println("success requestParamsMap " + requestParamsMap);
System.out.println("success fortResponseMap " + fortResponseMap);
JSONObject responseObject = new JSONObject(fortResponseMap);
try {
String response_message = responseObject.getString("response_message");
Toast.makeText(PaymentMethod.this, "" + response_message, Toast.LENGTH_LONG).show();
Intent intent = new Intent();
intent.putExtra("cardNo", cardNo);
intent.putExtra("cardId", cardId);
setResult(2, intent);
finish();
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Map<String, String> requestParamsMap, Map<String,
String> fortResponseMap) {
System.out.println("requestParamsMap " + requestParamsMap);
System.out.println("fortResponseMap " + fortResponseMap);
JSONObject responseObject = new JSONObject(fortResponseMap);
try {
String response_message = responseObject.getString("response_message");
Toast.makeText(PaymentMethod.this, response_message, Toast.LENGTH_LONG).show();
Intent intent = new Intent(PaymentMethod.this, PayFail.class);
intent.putExtra("cardNo", cardNo);
intent.putExtra("cardType", cardType);
intent.putExtra("cardPersonName", cardPersonName);
startActivity(intent);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
fortCallback.onActivityResult(requestCode, resultCode, data);
} catch (Exception e) {
Log.i("exception", e.getMessage());
}
}
private String getSignature() {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-256");
String text = "sadafdfeeeeaccess_code="+access_code+"
+ "device_id=" + FortSdk.getDeviceId(PaymentMethod.this)
+ "language=enmerchant_identifier="+merchant_identifier"+service_command=SDK_TOKENsadafdfeeee";
md.update(text.getBytes("UTF-8")); // Change this to "UTF-16" if needed
} catch (Exception e) {
e.printStackTrace();
}
byte[] digest = md.digest();
signature = String.format("%064x", new java.math.BigInteger(1, digest));
return signature;
}
public static String random() {
SecureRandom secureRandom = new SecureRandom();
return new BigInteger(40, secureRandom).toString(32);
}
答案 1 :(得分:0)
诀窍是什么,清单文件与payfort sdk冲突,你必须在应用程序标签中使用overover清单