¨4.0.1¨
This commit is contained in:
@@ -2,21 +2,22 @@
|
||||
|
||||
namespace Modules\Payment\Gateways;
|
||||
|
||||
use stdClass;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Payment\GatewayInterface;
|
||||
use Modules\Payment\Responses\AuthorizenetResponse;
|
||||
use net\authorize\api\contract\v1 as AnetAPI;
|
||||
use net\authorize\api\constants\ANetEnvironment;
|
||||
use net\authorize\api\controller as AnetController;
|
||||
use stdClass;
|
||||
use Modules\Payment\Responses\AuthorizenetResponse;
|
||||
|
||||
class AuthorizeNet implements GatewayInterface
|
||||
{
|
||||
public const SUPPORTED_CURRENCIES = ['CHF', 'DKK', 'EUR', 'GBP', 'NOK', 'PLN', 'SEK', 'USD', 'AUD', 'NZD', 'CAD'];
|
||||
public $label;
|
||||
public $description;
|
||||
|
||||
public const SUPPORTED_CURRENCIES = ['CHF', 'DKK', 'EUR', 'GBP', 'NOK', 'PLN', 'SEK', 'USD', 'AUD', 'NZD', 'CAD'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -24,6 +25,10 @@ class AuthorizeNet implements GatewayInterface
|
||||
$this->description = setting('authorizenet_description');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function purchase(Order $order, Request $request)
|
||||
{
|
||||
if (!in_array(currency(), self::SUPPORTED_CURRENCIES)) {
|
||||
@@ -35,18 +40,23 @@ class AuthorizeNet implements GatewayInterface
|
||||
return new AuthorizenetResponse($order, $response);
|
||||
}
|
||||
|
||||
|
||||
public function complete(Order $order)
|
||||
{
|
||||
return new AuthorizenetResponse($order, request());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private function getAnAcceptPaymentPage(Order $order)
|
||||
{
|
||||
define('AUTHORIZENET_LOG_FILE', 'phplog');
|
||||
$reference = 'ref' . time();
|
||||
|
||||
$callbackUrl = env('APP_ENV') === 'local' ? 'https://example.com/receipt' : $this->getRedirectUrl($order, $reference);
|
||||
$cancelUrl = env('APP_ENV') === 'local' ? 'https://example.com/cancel' : route('checkout.create');
|
||||
$callbackUrl = config('app.env') === 'local' ? 'https://example.com/receipt' : $this->getRedirectUrl($order, $reference);
|
||||
$cancelUrl = config('app.env') === 'local' ? 'https://example.com/cancel' : route('checkout.create');
|
||||
|
||||
//encode ampersand of the query parameter to make it compatible for api usage
|
||||
$encodedCallbackUrl = str_replace('&', '%26', $callbackUrl);
|
||||
@@ -92,14 +102,14 @@ class AuthorizeNet implements GatewayInterface
|
||||
|
||||
//execute request
|
||||
$controller = new AnetController\GetHostedPaymentPageController($request);
|
||||
$response = $controller->executeWithApiResponse(setting('authorizenet_test_mode') ? \net\authorize\api\constants\ANetEnvironment::SANDBOX : \net\authorize\api\constants\ANetEnvironment::PRODUCTION);
|
||||
$response = $controller->executeWithApiResponse(setting('authorizenet_test_mode') ? ANetEnvironment::SANDBOX : ANetEnvironment::PRODUCTION);
|
||||
|
||||
$extendedResponse = new stdClass();
|
||||
|
||||
if ($response != null && $response->getMessages()->getResultCode() == 'Ok') {
|
||||
$extendedResponse->token = $response->getToken();
|
||||
} else {
|
||||
$errorMessages = $response->getMessages()->getMessage();
|
||||
$errorMessage = $response->getMessages()->getMessage();
|
||||
|
||||
throw new Exception(trans('payment::messages.payment_gateway_error'));
|
||||
}
|
||||
@@ -110,6 +120,7 @@ class AuthorizeNet implements GatewayInterface
|
||||
return $extendedResponse;
|
||||
}
|
||||
|
||||
|
||||
private function getRedirectUrl($order, $reference)
|
||||
{
|
||||
return route('checkout.complete.store', ['orderId' => $order->id, 'paymentMethod' => 'authorizenet', 'reference' => $reference]);
|
||||
|
||||
Reference in New Issue
Block a user