我最近将webhooks集成到我的条带帐户中。 我还整合了一个clickfunnels页面。从我的登录页面触发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 webhooks而不是我的..如何解决这个问题所以我可以触发我的webhook和clickfunnels?
答案 0 :(得分:1)
点击程序会发送JSON数据而不是POST,因此您可能需要使用类似的方法来接收来自ClickFunnels的数据:
$json = file_get_contents('php://input');
$obj = json_decode($json, TRUE);