1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Payment webhook bug fixes

This commit is contained in:
Hillel Coren 2016-06-23 20:17:02 +03:00
parent 718aa6a966
commit d71017e203
6 changed files with 28 additions and 11 deletions

View File

@ -88,12 +88,12 @@ class Payment extends EntityModel
public function isPending()
{
return $this->payment_status_id = PAYMENT_STATUS_PENDING;
return $this->payment_status_id == PAYMENT_STATUS_PENDING;
}
public function isFailed()
{
return $this->payment_status_id = PAYMENT_STATUS_FAILED;
return $this->payment_status_id == PAYMENT_STATUS_FAILED;
}
public function isCompleted()

View File

@ -149,9 +149,21 @@ class PaymentMethod extends EntityModel
}
}
public function requiresDelayedAutoBill(){
public function requiresDelayedAutoBill()
{
return $this->payment_type_id == PAYMENT_TYPE_ACH;
}
public function gatewayType()
{
if ($this->payment_type_id == PAYMENT_TYPE_ACH) {
return GATEWAY_TYPE_BANK_TRANSFER;
} elseif ($this->payment_type_id == PAYMENT_TYPE_PAYPAL) {
return GATEWAY_TYPE_PAYPAL;
} else {
return GATEWAY_TYPE_TOKEN;
}
}
}
PaymentMethod::deleting(function($paymentMethod) {

View File

@ -42,9 +42,14 @@ class BasePaymentDriver
return $this->accountGateway->gateway_id == $gatewayId;
}
protected function isGatewayType($gatewayType)
// optionally pass a paymentMethod to determine the type from the token
protected function isGatewayType($gatewayType, $paymentMethod = false)
{
return $this->gatewayType === $gatewayType;
if ($paymentMethod) {
return $paymentMethod->gatewayType() == $gatewayType;
} else {
return $this->gatewayType === $gatewayType;
}
}
public function gatewayTypes()
@ -547,7 +552,7 @@ class BasePaymentDriver
$payment->payment_date = date_create()->format('Y-m-d');
$payment->ip = Request::ip();
$payment = $this->creatingPayment($payment);
$payment = $this->creatingPayment($payment, $paymentMethod);
if ($paymentMethod) {
$payment->last4 = $paymentMethod->last4;
@ -618,7 +623,7 @@ class BasePaymentDriver
return $payment;
}
protected function creatingPayment($payment)
protected function creatingPayment($payment, $paymentMethod)
{
return $payment;
}

View File

@ -70,7 +70,7 @@ class BraintreePaymentDriver extends BasePaymentDriver
$data['device_data'] = $deviceData;
}
if ($this->isGatewayType(GATEWAY_TYPE_PAYPAL)) {
if ($this->isGatewayType(GATEWAY_TYPE_PAYPAL, $paymentMethod)) {
$data['ButtonSource'] = 'InvoiceNinja_SP';
}

View File

@ -20,7 +20,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
return $data;
}
protected function creatingPayment($payment)
protected function creatingPayment($payment, $paymentMethod)
{
$payment->payer_id = $this->input['PayerID'];

View File

@ -168,9 +168,9 @@ class StripePaymentDriver extends BasePaymentDriver
return $paymentMethod;
}
protected function creatingPayment($payment)
protected function creatingPayment($payment, $paymentMethod)
{
if ($this->isGatewayType(GATEWAY_TYPE_BANK_TRANSFER)) {
if ($this->isGatewayType(GATEWAY_TYPE_BANK_TRANSFER, $paymentMethod)) {
$payment->payment_status_id = $this->purchaseResponse['status'] == 'succeeded' ? PAYMENT_STATUS_COMPLETED : PAYMENT_STATUS_PENDING;
}