【发布时间】:2018-03-21 18:23:52
【问题描述】:
\Stripe\Stripe::setApiKey
此 API 在 webhook 中完美运行并获得完美结果。但是当我使用订阅 api 时:
\Stripe\Subscription::retrieve
它给了我测试 webhook 错误:500。
这是我的代码:
$stripe_secret_key = '*****';
$dbname="****"; // database name
$usertable="*****"; // webhook table
require_once('wp-config.php');
$connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db($dbname, $connection);
require_once('webhook/vendor/autoload.php');
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey($stripe_secret_key);
// Retrieve the request's body and parse it as JSON
$input = @file_get_contents("php://input");
$event_json = json_decode($input);
$event_type = $event_json->type;
$chargeId = $event_json->data->object->charge;
$subcriptionKey = $event_json->data->object->lines->data[0]->id;
$customerId = $event_json->data->object->customer;
$amoutDue = $event_json->data->object->amount_due;
$paidStatus = $event_json->data->object->paid;
$interval = $event_json->data->object->lines->data[0]->plan->interval_count;
//insert query
$sql = "INSERT INTO epti_webhook ".
"(subscription_id,charge_id, customer_id,event_type, month_interval, paidStatus, data_response) "."VALUES ".
"('$subcriptionKey','$chargeId','$customerId','$event_type','$interval','$paidStatus','$input')";
$retval = mysql_query( $sql, $connection );
if(! $retval ) {
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
//count query
$result=mysql_query("SELECT count(*) as total from epti_webhook where subscription_id = '".$subcriptionKey."'");
$data=mysql_fetch_assoc($result);
echo $data['total'].'===';
if($data['total'] > '1'){
//issue is coming here
$sub = \Stripe\Subscription::retrieve("sub_A****");
$sub->cancel();
}
http_response_code(200); // PHP 5.4 or greater`
需要帮助的人。我也更新了最新的条纹,但它给了我同样的错误。 提前谢谢你
【问题讨论】:
-
我厌倦了从客户 ID 中检索详细信息,然后尝试取消订阅,它可以工作
标签: php wordpress api stripe-payments payment-gateway