mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
wip
This commit is contained in:
parent
0c7ae3bca8
commit
d7277b7c6d
@ -55,7 +55,7 @@ trait Utilities
|
|||||||
return round($amount * 100);
|
return round($amount * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processSuccessfulPayment(Payment $_payment)
|
private function processSuccessfulPayment(Payment $_payment, $return_payment = false)
|
||||||
{
|
{
|
||||||
if ($this->getParent()->payment_hash->data->store_card) {
|
if ($this->getParent()->payment_hash->data->store_card) {
|
||||||
$this->storePaymentMethod($_payment);
|
$this->storePaymentMethod($_payment);
|
||||||
@ -78,10 +78,14 @@ trait Utilities
|
|||||||
$this->getParent()->client
|
$this->getParent()->client
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($return_payment) {
|
||||||
|
return $payment;
|
||||||
|
}
|
||||||
|
|
||||||
return redirect()->route('client.payments.show', ['payment' => $this->getParent()->encodePrimaryKey($payment->id)]);
|
return redirect()->route('client.payments.show', ['payment' => $this->getParent()->encodePrimaryKey($payment->id)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processUnsuccessfulPayment(Payment $_payment)
|
public function processUnsuccessfulPayment(Payment $_payment, $throw_exception = true)
|
||||||
{
|
{
|
||||||
PaymentFailureMailer::dispatch(
|
PaymentFailureMailer::dispatch(
|
||||||
$this->getParent()->client,
|
$this->getParent()->client,
|
||||||
@ -103,7 +107,9 @@ trait Utilities
|
|||||||
$this->getParent()->client
|
$this->getParent()->client
|
||||||
);
|
);
|
||||||
|
|
||||||
throw new PaymentFailed($_payment->status, $_payment->http_code);
|
if ($throw_exception) {
|
||||||
|
throw new PaymentFailed($_payment->status, $_payment->http_code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processPendingPayment(Payment $_payment)
|
private function processPendingPayment(Payment $_payment)
|
||||||
|
@ -12,18 +12,24 @@
|
|||||||
|
|
||||||
namespace App\PaymentDrivers;
|
namespace App\PaymentDrivers;
|
||||||
|
|
||||||
|
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
|
||||||
use App\Http\Requests\Payments\PaymentWebhookRequest;
|
use App\Http\Requests\Payments\PaymentWebhookRequest;
|
||||||
|
use App\Jobs\Mail\PaymentFailureMailer;
|
||||||
|
use App\Jobs\Util\SystemLogger;
|
||||||
use App\Models\ClientGatewayToken;
|
use App\Models\ClientGatewayToken;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\GatewayType;
|
use App\Models\GatewayType;
|
||||||
|
use App\Models\Invoice;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\PaymentHash;
|
use App\Models\PaymentHash;
|
||||||
|
use App\Models\PaymentType;
|
||||||
use App\Models\SystemLog;
|
use App\Models\SystemLog;
|
||||||
use App\PaymentDrivers\CheckoutCom\CreditCard;
|
use App\PaymentDrivers\CheckoutCom\CreditCard;
|
||||||
use App\PaymentDrivers\CheckoutCom\Utilities;
|
use App\PaymentDrivers\CheckoutCom\Utilities;
|
||||||
use App\Utils\Traits\SystemLogTrait;
|
use App\Utils\Traits\SystemLogTrait;
|
||||||
use Checkout\CheckoutApi;
|
use Checkout\CheckoutApi;
|
||||||
use Checkout\Library\Exceptions\CheckoutHttpException;
|
use Checkout\Library\Exceptions\CheckoutHttpException;
|
||||||
|
use Checkout\Models\Payments\IdSource;
|
||||||
use Checkout\Models\Payments\Refund;
|
use Checkout\Models\Payments\Refund;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
@ -96,8 +102,8 @@ class CheckoutComPaymentDriver extends BaseDriver
|
|||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$config = [
|
$config = [
|
||||||
'secret' => $this->company_gateway->getConfigField('secretApiKey'),
|
'secret' => $this->company_gateway->getConfigField('secretApiKey'),
|
||||||
'public' => $this->company_gateway->getConfigField('publicApiKey'),
|
'public' => $this->company_gateway->getConfigField('publicApiKey'),
|
||||||
'sandbox' => $this->company_gateway->getConfigField('testMode'),
|
'sandbox' => $this->company_gateway->getConfigField('testMode'),
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -108,7 +114,7 @@ class CheckoutComPaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Process different view depending on payment type
|
* Process different view depending on payment type
|
||||||
* @param int $gateway_type_id The gateway type
|
* @param int $gateway_type_id The gateway type
|
||||||
* @return string The view string
|
* @return string The view string
|
||||||
*/
|
*/
|
||||||
public function viewForType($gateway_type_id)
|
public function viewForType($gateway_type_id)
|
||||||
@ -132,7 +138,7 @@ class CheckoutComPaymentDriver extends BaseDriver
|
|||||||
/**
|
/**
|
||||||
* Payment View
|
* Payment View
|
||||||
*
|
*
|
||||||
* @param array $data Payment data array
|
* @param array $data Payment data array
|
||||||
* @return view The payment view
|
* @return view The payment view
|
||||||
*/
|
*/
|
||||||
public function processPaymentView(array $data)
|
public function processPaymentView(array $data)
|
||||||
@ -143,7 +149,7 @@ class CheckoutComPaymentDriver extends BaseDriver
|
|||||||
/**
|
/**
|
||||||
* Process the payment response
|
* Process the payment response
|
||||||
*
|
*
|
||||||
* @param Request $request The payment request
|
* @param Request $request The payment request
|
||||||
* @return view The payment response view
|
* @return view The payment response view
|
||||||
*/
|
*/
|
||||||
public function processPaymentResponse($request)
|
public function processPaymentResponse($request)
|
||||||
@ -188,7 +194,54 @@ class CheckoutComPaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
|
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
|
||||||
{
|
{
|
||||||
// ..
|
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
|
||||||
|
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->first();
|
||||||
|
|
||||||
|
if ($invoice) {
|
||||||
|
$description = "Invoice {$invoice->number} for {$amount} for client {$this->client->present()->name()}";
|
||||||
|
} else {
|
||||||
|
$description = "Payment with no invoice for amount {$amount} for client {$this->client->present()->name()}";
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
$method = new IdSource($cgt->token);
|
||||||
|
|
||||||
|
$payment = new \Checkout\Models\Payments\Payment($method, $this->client->getCurrencyCode());
|
||||||
|
$payment->amount = $this->convertToCheckoutAmount($amount, $this->client->getCurrencyCode());
|
||||||
|
$payment->reference = $cgt->meta->last4 . '-' . now();
|
||||||
|
|
||||||
|
$request = new PaymentResponseRequest();
|
||||||
|
$request->setMethod('POST');
|
||||||
|
$request->request->add(['payment_hash' => $payment_hash]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->gateway->payments()->request($payment);
|
||||||
|
|
||||||
|
if ($response->status == 'Authorized') {
|
||||||
|
$this->confirmGatewayFee($request);
|
||||||
|
|
||||||
|
return $this->processSuccessfulPayment($response, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($response->status == 'Declined') {
|
||||||
|
$this->unWindGatewayFees($payment_hash);
|
||||||
|
|
||||||
|
PaymentFailureMailer::dispatch(
|
||||||
|
$this->client, $response->response_summary,
|
||||||
|
$this->client->company,
|
||||||
|
$this->payment_hash->data->value
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->processUnsuccessfulPayment($response, false);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (\Exception | CheckoutHttpException $e) {
|
||||||
|
$this->unWindGatewayFees($payment_hash);
|
||||||
|
|
||||||
|
// ..
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processWebhookRequest(PaymentWebhookRequest $request, Payment $payment = null)
|
public function processWebhookRequest(PaymentWebhookRequest $request, Payment $payment = null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user