Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Pckg/Payment/Form/PlatformSettings/Bankart.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function initFields()
$this->addText('apiPassword')->setLabel('API password')->addValidator(new RequireWhenEnabled($this));
$this->addText('publicIntegrationKey')->setLabel('Public integration key')->addValidator(new RequireWhenEnabled($this));
$this->addText('maxInstalments')->setLabel('Max instalments')->addValidator(new RequireWhenEnabled($this));
$this->addText('transactionMethod')->setLabel('Transaction method')->addValidator(new RequireWhenEnabled($this));
$this->addText('url')->setLabel('API URL')->addValidator(new RequireWhenEnabled($this));

return $this;
Expand Down
38 changes: 34 additions & 4 deletions src/Pckg/Payment/Handler/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Pckg\Payment\Adapter\Environment;
use Pckg\Payment\Adapter\Log;
use Pckg\Payment\Adapter\Order;
use Pckg\Payment\Entity\Payments;
use Pckg\Payment\Record\Payment;

abstract class AbstractHandler implements Handler
Expand Down Expand Up @@ -160,6 +161,8 @@ public function setPaymentId($paymentId)

public function waitPayment($description, $log, $transactionId, $status = 'waiting')
{
try {
(new Payments())->transaction(function() use ($description, $log, $transactionId, $status){
$this->paymentRecord->addLog($status, $log);

$this->order->getBills()->keyBy('order_id')->each(function(OrdersBill $ordersBill) use ($description) {
Expand All @@ -178,20 +181,47 @@ public function waitPayment($description, $log, $transactionId, $status = 'waiti
'status' => $status,
'transaction_id' => $transactionId,
]);

throw new \Exception("Reverted");
});
} catch (\Throwable $e) {
ddd(exception($e));
}
}

/**
* @param $description
* @param $log
* @param $transactionId
* @param string $status
*
* Used to confirm transaction and related orders, packets and instalments.
*/
public function approvePayment($description, $log, $transactionId, $status = 'approved')
{
$this->paymentRecord->addLog($status, $log);

$this->order->getBills()->each(function(OrdersBill $ordersBill) use ($description) {
$this->order->getBills()->each(function (OrdersBill $ordersBill) use ($description) {
$ordersBill->confirm($description);
});

$this->paymentRecord->setAndSave([
'status' => $status,
'transaction_id' => $transactionId,
]);
'status' => $status,
'transaction_id' => $transactionId,
]);
}

/**
* Used to pre-authorize transaction.
* Should decrease stock?
*/
public function authorizePayment($description, $log, $transactionId, $status = 'authorized')
{
$this->paymentRecord->addLog($status, $log);
$this->paymentRecord->setAndSave([
'status' => $status,
'transaction_id' => $transactionId,
]);
}

public function approveRefund($description, $log, $transactionId)
Expand Down
85 changes: 75 additions & 10 deletions src/Pckg/Payment/Handler/Omnipay/AbstractOmnipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
abstract class AbstractOmnipay extends AbstractHandler
{

const TRANSACTION_PURCHASE = 'purchase';

const TRANSACTION_PREAUTHORIZATION = 'authorize';

/**
* @var string
*/
Expand Down Expand Up @@ -80,12 +84,34 @@ public function initPayment()
return $this->postStart();
}

/**
* @return string
* Return "purchase" or "authorization"
*/
public function getOmnipayTransactionMethod()
{
return $this->environment->config($this->handler . '.transactionMethod') ?? static::TRANSACTION_PURCHASE;
}

/**
* @param $request
* @return array|mixed
*/
public function sendOmnipayEnrichedData($request)
{
return $request->sendData($this->enrichOmnipayOrderDetails($request->getData()));
}

/**
* @throws \Exception
*/
public function postStart()
{
if (!$this->client->supportsPurchase()) {
/**
* Check for purchase / authorize support.
*/
$transactionMethod = $this->getOmnipayTransactionMethod();
if (!$this->client->{['purchase' => 'supportsPurchase', 'authorize' => 'supportsAuthorize'][$transactionMethod]}()) {
throw new \Exception('Gateway does not support purchase()');
}

Expand All @@ -94,21 +120,26 @@ public function postStart()
* Get customer and order details.
* Make the purchase call.
*/
$request = $this->client->purchase($this->getOmnipayOrderDetails());
$request = $this->client->{$transactionMethod}($this->getOmnipayOrderDetails());

/**
* Some parameters are not supported by the original gateway.
*/
$response = $request->sendData($this->enrichOmnipayOrderDetails($request->getData()));
$response = $this->sendOmnipayEnrichedData();

/**
* Firs check for a redirect.
* First check for a redirect.
* Send the redirect to the frontend.
*/
if ($response->isRedirect()) {
$redirect = $response->getRedirectUrl();
$method = $response->getRedirectMethod();

/**
* GET method is redirected.
*/
if ($method === 'GET') {
$this->paymentRecord->addLog('redirecting', 'Redirected');
return [
'success' => true,
'redirect' => $redirect,
Expand All @@ -118,6 +149,7 @@ public function postStart()
/**
* Submit the form with data on the frontend.
*/
$this->paymentRecord->addLog('redirecting', 'Submitting form');
return [
'success' => true,
'form' => [
Expand All @@ -137,19 +169,25 @@ public function postStart()
$this->paymentRecord->setAndSave([
'payment_id' => $response->getTransactionReference(),
]);
$this->paymentRecord->addLog('success', 'Success ' . $transactionMethod);

return [
'success' => true,
'modal' => 'success',
];
}

$this->paymentRecord->addLog('error', $response->getMessage() . ' ' . $response->getCode());

return [
'success' => false,
'message' => $response->getMessage(),
'code' => $response->getCode(),
];
} catch (\Throwable $e) {

$this->paymentRecord->addLog('error', exception($e));

return [
'success' => false,
'modal' => 'error',
Expand All @@ -159,6 +197,26 @@ public function postStart()
}
}

public function capture($notes = null, $log = [])
{
if (!$this->client->supportsCapture()) {
throw new \Exception('Client does not support capture');
}

$response = $this->client->capture()->send();

if ($response->isSuccessful()) {
$myTransactionId = $response->getTransactionId();
$gatewayTransactionId = $response->getTransactionReference();

$this->approvePayment(trim(Convention::toCamel($this->handler) . ' #' . $gatewayTransactionId . $notes), ($log ? [$log, $response] : $response), $gatewayTransactionId);

return true;
}

return false;
}

/**
* @return bool|void
*/
Expand All @@ -169,6 +227,7 @@ public function completePurchase()
}

$response = $this->client->completePurchase()->send();

if ($response->isSuccessful()) {
$myTransactionId = $response->getTransactionId();
$gatewayTransactionId = $response->getTransactionReference();
Expand Down Expand Up @@ -197,12 +256,18 @@ public function postNotification()
if ($response->getTransactionStatus() === NotificationInterface::STATUS_COMPLETED) {
$myTransactionId = $response->getTransactionId();
$gatewayTransactionId = $response->getTransactionReference();

$this->approvePayment(Convention::toCamel($this->handler) . ' #' . $gatewayTransactionId, $response, $gatewayTransactionId);

return [
'success' => true,
];

/**
* Is every transaction approved?
* Shouldn't we only pre-authorize some?
*/
if ($this->getOmnipayTransactionMethod() === static::TRANSACTION_PURCHASE) {
$this->approvePayment(Convention::toCamel($this->handler) . ' #' . $gatewayTransactionId, $response, $gatewayTransactionId);
} else {
$this->authorizePayment(Convention::toCamel($this->handler) . ' #' . $gatewayTransactionId, $response, $gatewayTransactionId);
}
} else {
$this->errorPayment($response);
}

echo "OK";
Expand Down
2 changes: 1 addition & 1 deletion src/Pckg/Payment/Handler/Valu.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function getNotification()
$sConfirmationSignature = ValuHelper::Functions_RequestString("ConfirmationSignature", 250);
$nTarifficationError = ValuHelper::Functions_RequestNumber("TARIFFICATIONERROR", 0, 1, 1);
$sConfirmationIDStatus = ValuHelper::Functions_RequestString("ConfirmationIDStatus", 32);
$sIP = ValuHelper::Functions_GetServerVariable('REMOTE_ADDR');
$sIP = request()->clientIp();
$sOutput = "<error>1</error>";

$this->paymentRecord->addLog('check', ['confirmationSignature' => $sConfirmationSignature, 'tarifficationError' => $nTarifficationError, 'confirmationIdStatus' => $sConfirmationIDStatus]);
Expand Down
16 changes: 11 additions & 5 deletions src/Pckg/Payment/View/platformSettings/bankart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@
</div>
</div>

<div class="form-group">
<label>Public integration key</label>
<div>
<input type="text" v-model="paymentMethod.publicIntegrationKey" class="form-control"/>
</div>
<div class="form-group">
<label>Public integration key</label>
<div>
<input type="text" v-model="paymentMethod.publicIntegrationKey" class="form-control"/>
</div>
</div>

<form-group label="Transaction method"
type="select:single"
:options="{options:{purchase:'Purchase',authorize:'Pre-authorization'}}"
v-model="paymentMethod.transactionMethod"></form-group>

<form-group label="Max number of instalments"
type="number"
Expand All @@ -77,6 +82,7 @@
sharedSecret: this.paymentMethod.sharedSecret,
publicIntegrationKey: this.paymentMethod.publicIntegrationKey,
maxInstalments: this.paymentMethod.maxInstalments,
transactionMethod: this.paymentMethod.transactionMethod,
url: this.paymentMethod.url,
};
}
Expand Down