Stripe + Clickfunnels 和 webhooks
Stripe + Clickfunnels and webhooks
我最近将 webhooks 集成到我的 stripe 帐户中。
我还集成了一个点击漏斗页面。从我的登录页面触发 charge.successful 事件后,我希望我的 webhook 得到一些 POST。
<?php namespace Laravel\Cashier;
use Exception;
use Stripe_Event;
use Stripe_Customer;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Person;
use Order;
use OrderItem;
use Item;
class WebhookController extends Controller
{
/**
* Handle a Stripe webhook call.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handleWebhook()
{
$payload = $this->getJsonPayload();
try {
$var = Stripe_Event::retrieve($payload['id']);
} catch (Exception $e) {
return $e->getMessage();
}
if (!$this->eventExistsOnStripe($payload['id'])) {
return "doesn't exist onstripe";
}
$method = 'handle' . studly_case(str_replace('.', '_', $payload['type']));
if (method_exists($this, $method)) {
return $this->{$method}($payload);
} else {
return $this->missingMethod();
}
}
/**
* Verify with Stripe that the event is genuine.
*
* @param string $id
* @return bool
*/
protected function eventExistsOnStripe($id)
{
try {
return !is_null(Stripe_Event::retrieve($id));
} catch (Exception $e) {
return false;
}
}
protected function handleChargeSucceeded(array $payload)
{
return true
}
/**
* Handle a failed payment from a Stripe subscription.
*
* @param array $payload
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function handleInvoicePaymentFailed(array $payload)
{
if ($this->tooManyFailedPayments($payload)) {
$billable = $this->getBillable($payload['data']['object']['customer']);
if ($billable) $billable->subscription()->cancel();
}
return new Response('Webhook Handled', 200);
}
/**
* Determine if the invoice has too many failed attempts.
*
* @param array $payload
* @return bool
*/
protected function tooManyFailedPayments(array $payload)
{
return $payload['data']['object']['attempt_count'] > 3;
}
/**
* Get the billable entity instance by Stripe ID.
*
* @param string $stripeId
* @return \Laravel\Cashier\BillableInterface
*/
protected function getBillable($stripeId)
{
return App::make('Laravel\Cashier\BillableRepositoryInterface')->find($stripeId);
}
/**
* Get the JSON payload for the request.
*
* @return array
*/
protected function getJsonPayload()
{
return (array)json_decode(Request::getContent(), true);
}
/**
* Handle calls to missing methods on the controller.
*
* @param array $parameters
* @return mixed
*/
public function missingMethod($parameters = array())
{
return new Response;
}
}
我也把代码放在 this link 上,因为它包含太多方法。
但情况似乎并非如此。
当我转到 Stripe 事件日志时,我可以看到只有 clickfunnel webhook 被触发,而不是我的。如何解决这个问题以便我可以同时触发我的 webhook 和 clickfunnels?
点击漏斗发送 JSON 数据而不是 POST 因此您可能需要使用类似这样的方法从 ClickFunnels 接收数据:
$json = file_get_contents('php://input');
$obj = json_decode($json, TRUE);
我最近将 webhooks 集成到我的 stripe 帐户中。 我还集成了一个点击漏斗页面。从我的登录页面触发 charge.successful 事件后,我希望我的 webhook 得到一些 POST。
<?php namespace Laravel\Cashier;
use Exception;
use Stripe_Event;
use Stripe_Customer;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Person;
use Order;
use OrderItem;
use Item;
class WebhookController extends Controller
{
/**
* Handle a Stripe webhook call.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handleWebhook()
{
$payload = $this->getJsonPayload();
try {
$var = Stripe_Event::retrieve($payload['id']);
} catch (Exception $e) {
return $e->getMessage();
}
if (!$this->eventExistsOnStripe($payload['id'])) {
return "doesn't exist onstripe";
}
$method = 'handle' . studly_case(str_replace('.', '_', $payload['type']));
if (method_exists($this, $method)) {
return $this->{$method}($payload);
} else {
return $this->missingMethod();
}
}
/**
* Verify with Stripe that the event is genuine.
*
* @param string $id
* @return bool
*/
protected function eventExistsOnStripe($id)
{
try {
return !is_null(Stripe_Event::retrieve($id));
} catch (Exception $e) {
return false;
}
}
protected function handleChargeSucceeded(array $payload)
{
return true
}
/**
* Handle a failed payment from a Stripe subscription.
*
* @param array $payload
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function handleInvoicePaymentFailed(array $payload)
{
if ($this->tooManyFailedPayments($payload)) {
$billable = $this->getBillable($payload['data']['object']['customer']);
if ($billable) $billable->subscription()->cancel();
}
return new Response('Webhook Handled', 200);
}
/**
* Determine if the invoice has too many failed attempts.
*
* @param array $payload
* @return bool
*/
protected function tooManyFailedPayments(array $payload)
{
return $payload['data']['object']['attempt_count'] > 3;
}
/**
* Get the billable entity instance by Stripe ID.
*
* @param string $stripeId
* @return \Laravel\Cashier\BillableInterface
*/
protected function getBillable($stripeId)
{
return App::make('Laravel\Cashier\BillableRepositoryInterface')->find($stripeId);
}
/**
* Get the JSON payload for the request.
*
* @return array
*/
protected function getJsonPayload()
{
return (array)json_decode(Request::getContent(), true);
}
/**
* Handle calls to missing methods on the controller.
*
* @param array $parameters
* @return mixed
*/
public function missingMethod($parameters = array())
{
return new Response;
}
}
我也把代码放在 this link 上,因为它包含太多方法。
但情况似乎并非如此。
当我转到 Stripe 事件日志时,我可以看到只有 clickfunnel webhook 被触发,而不是我的。如何解决这个问题以便我可以同时触发我的 webhook 和 clickfunnels?
点击漏斗发送 JSON 数据而不是 POST 因此您可能需要使用类似这样的方法从 ClickFunnels 接收数据:
$json = file_get_contents('php://input');
$obj = json_decode($json, TRUE);