【发布时间】:2015-01-21 02:46:40
【问题描述】:
我只是想让测试正常工作,但似乎无法做到,任何帮助将不胜感激。我不断收到条带无效请求错误。我尝试了多种方法,但无法使其正常工作。
安卓代码:
private void deposit() throws AuthenticationException {
//bp.purchase("android.test.purchased");
//bp.consumePurchase("android.test.purchased");
Card card = new Card("4242-4242-4242-4242", 12, 2016, "123");
if ( !card.validateCard() ) {
// Show errors
Toast.makeText(getApplicationContext(), "Incorrect card Information", Toast.LENGTH_SHORT).show();
}
else {
Stripe stripe = new Stripe("pk_test_t9ODKMyhv3BwKiEHdQE0bmHi");
stripe.createToken(
card,
new TokenCallback() {
public void onSuccess(Token token) {
// Send token to your server
String url = "/BettingXChange/charge.php";
//populate json object with user entered data
try {
chargeInfo.put("stripeToken", token);
Log.e("token", String.valueOf(token));
chargeInfo.put("user", savedUserID);
} catch (JSONException e) {
//Log the exception
Log.e("JSON Exception", e.toString());
}
//Set the response listener
Response.Listener responseListener = new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
//Handle the json response
try {
//Assign member variables upon Json Response
responseSuccess = response.getInt("success");
} catch (JSONException e) {
//Log the exception
Log.e("JSON Exception", e.toString());
}
//If charge successful, move to main app
if (responseSuccess == 1) {
Toast.makeText(getApplicationContext(), "YAYY", Toast.LENGTH_SHORT).show();
}
}
};
//Set the error response listener
Response.ErrorListener responseErrorListener = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//Log the error
Log.e("Response Error", error.toString());
//Make a toast
Toast.makeText(getApplicationContext(),
"sorry",
Toast.LENGTH_SHORT).show();
}
};
//Use the request handler to send the Volley json POST request
requestHandler.post(url, chargeInfo, responseListener, responseErrorListener);
}
public void onError(Exception error) {
// Show localized error message
/*\
Toast.makeText(getContext(),
error.getLocalizedString(getContext()),
Toast.LENGTH_LONG
).show();*/
}
}
);
}
}
php代码:
<?php
require_once("stripe-php-1.17.5/lib/Stripe.php");
mysql_connect("localhost","root","password");
mysql_select_db("testapp");
$body = file_get_contents('php://input');
$postvars = json_decode($body, true);
$token = $postvars["stripeToken"];
$user = $postvars["user"];
// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account
Stripe::setApiKey("sk_test_BrWE3ndM19knCYGAGj27Wix7");
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = Stripe_Charge::create(array(
"amount" => 1000, // amount in cents, again
"currency" => "usd",
"card" => $token,
"description" => "payinguser@example.com")
);
//add money to users account
//get total money from people involved in bet
$sql = mysql_query("SELECT currency FROM `people` WHERE id = '".$user."'");
while($e=mysql_fetch_assoc($sql)){
$output1[]=$e;
}
$userAmount = $output1[0]['currency'];
$remainingUserBalance = (1000/100.0)+$userAmount;
$sql = "UPDATE `people` set currency = '".$remainingUserBalance."' WHERE id = '".$user."'";
if(mysql_query($sql)){
$response["success"] = $token;
echo $response;
}
} catch(Stripe_CardError $e) {
// The card has been declined
echo "carderror";
}
catch (Stripe_InvalidRequestError $e) {
// You screwed up in your programming. Shouldn't happen!
echo "uh oh";
}
catch(Stripe_Error $e){
//
//echo "stripe error";
//echo $e;
}
mysql_close();
?>
【问题讨论】:
-
你能告诉我你是如何实现响应类的吗?我也在编写一个带有条带实现的应用程序。