mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 10:44:29 -04:00
Working on gocardless
This commit is contained in:
parent
9f350c0c5b
commit
ac55d5849f
@ -299,7 +299,7 @@ class OnlinePaymentController extends BaseController
|
|||||||
|
|
||||||
return response()->json(['message' => $result]);
|
return response()->json(['message' => $result]);
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
if (! Uitls::isNinjaProd()) {
|
if (! Utils::isNinjaProd()) {
|
||||||
Utils::logError($exception->getMessage(), 'HOOK');
|
Utils::logError($exception->getMessage(), 'HOOK');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Ninja\PaymentDrivers;
|
namespace App\Ninja\PaymentDrivers;
|
||||||
|
|
||||||
use Session;
|
use Session;
|
||||||
|
use App\Models\Payment;
|
||||||
|
|
||||||
class GoCardlessV2RedirectPaymentDriver extends BasePaymentDriver
|
class GoCardlessV2RedirectPaymentDriver extends BasePaymentDriver
|
||||||
{
|
{
|
||||||
@ -71,45 +72,56 @@ class GoCardlessV2RedirectPaymentDriver extends BasePaymentDriver
|
|||||||
|
|
||||||
protected function creatingPayment($payment, $paymentMethod)
|
protected function creatingPayment($payment, $paymentMethod)
|
||||||
{
|
{
|
||||||
\Log::info(json_encode($this->purchaseResponse));
|
$payment->payment_status_id = PAYMENT_STATUS_PENDING;
|
||||||
//$payment->payment_status_id = $this->purchaseResponse['status'] == 'succeeded' ? PAYMENT_STATUS_COMPLETED : PAYMENT_STATUS_PENDING;
|
|
||||||
|
|
||||||
return $payment;
|
return $payment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleWebHook($input)
|
public function handleWebHook($input)
|
||||||
{
|
{
|
||||||
\Log::info('handleWebHook... ' . $_SERVER['HTTP_WEBHOOK_SIGNATURE']);
|
$accountGateway = $this->accountGateway;
|
||||||
\Log::info(json_encode($input));
|
$accountId = $accountGateway->account_id;
|
||||||
|
|
||||||
/*
|
$token = env('GC_WEBHOOK_SECRET');
|
||||||
// We recommend storing your webhook endpoint secret in an environment variable
|
$rawPayload = file_get_contents('php://input');
|
||||||
// for security, but you could include it as a string directly in your code
|
$providedSignature = $_SERVER['HTTP_WEBHOOK_SIGNATURE'];
|
||||||
$token = getenv("GC_WEBHOOK_SECRET");
|
$calculatedSignature = hash_hmac('sha256', $rawPayload, $token);
|
||||||
|
|
||||||
$raw_payload = file_get_contents('php://input');
|
if (! hash_equals($providedSignature, $calculatedSignature)) {
|
||||||
|
throw new Exception('Signature does not match');
|
||||||
$headers = getallheaders();
|
|
||||||
$provided_signature = $headers["Webhook-Signature"];
|
|
||||||
|
|
||||||
$calculated_signature = hash_hmac("sha256", $raw_payload, $token);
|
|
||||||
|
|
||||||
if ($provided_signature == $calculated_signature) {
|
|
||||||
// Process the events...
|
|
||||||
|
|
||||||
header("HTTP/1.1 200 OK");
|
|
||||||
} else {
|
|
||||||
header("HTTP/1.1 498 Invalid Token");
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
$event = $this->gateway()->parseNotification(
|
foreach ($input['events'] as $event) {
|
||||||
file_get_contents('php://input'),
|
$type = $event['resource_type'];
|
||||||
$_SERVER['HTTP_WEBHOOK_SIGNATURE']
|
$action = $event['action'];
|
||||||
);
|
|
||||||
|
|
||||||
\Log::info('event:');
|
$supported = [
|
||||||
\Log::info(json_encode($event));
|
'paid_out',
|
||||||
|
'failed',
|
||||||
|
'charged_back',
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($type != 'payments' || ! in_array($action, $supported)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sourceRef = isset($event['links']['payment']) ? $event['links']['payment'] : false;
|
||||||
|
$payment = Payment::scope(false, $accountId)->where('transaction_reference', '=', $sourceRef)->first();
|
||||||
|
|
||||||
|
if (! $payment) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action == 'failed' || $action == 'charged_back') {
|
||||||
|
if (! $payment->isFailed()) {
|
||||||
|
$payment->markFailed($event['details']['description']);
|
||||||
|
|
||||||
|
$userMailer = app('App\Ninja\Mailers\UserMailer');
|
||||||
|
$userMailer->sendNotification($payment->user, $payment->invoice, 'payment_failed', $payment);
|
||||||
|
}
|
||||||
|
} elseif ($action == 'paid_out') {
|
||||||
|
$payment->markComplete();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user