Skip to content

Commit

Permalink
Merge pull request #31 from david-fiaty-cko/master
Browse files Browse the repository at this point in the history
Checkout.com Magento 2 Module - v1.0.12
  • Loading branch information
nicolas-maalouf-cko authored Nov 16, 2017
2 parents 90c95ee + a5017d6 commit 98e1888
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 122 deletions.
2 changes: 1 addition & 1 deletion Gateway/Http/Client/AbstractTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function __construct(
*/
public function placeRequest(TransferInterface $transferObject) {

if($this->gatewayResponseHolder->hasCallbackResponse()) {
if ($this->gatewayResponseHolder->hasCallbackResponse()) {
$response = $this->gatewayResponseHolder->getGatewayResponse();

$this->logger->debug([
Expand Down
78 changes: 0 additions & 78 deletions Gateway/Response/CreateInvoiceHandler.php

This file was deleted.

41 changes: 35 additions & 6 deletions Model/Resource/MobilePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,25 @@
use Magento\Framework\HTTP\ZendClient;
use Magento\Payment\Gateway\Http\TransferInterface;
use Magento\Payment\Gateway\Http\ClientException;
use CheckoutCom\Magento2\Api\MobilePaymentInterface;
use CheckoutCom\Magento2\Gateway\Http\TransferFactory;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Catalog\Model\Product;
use CheckoutCom\Magento2\Gateway\Config\Config as GatewayConfig;

use Magento\Quote\Model\QuoteFactory;
use Magento\Store\Model\StoreManagerInterface;
use CheckoutCom\Magento2\Model\Service\OrderService;
use Magento\Quote\Model\Quote;
use Magento\Customer\Model\Address;
use Magento\Checkout\Model\Type\Onepage;
use CheckoutCom\Magento2\Model\Service\OrderService;
use CheckoutCom\Magento2\Model\Ui\ConfigProvider;
use CheckoutCom\Magento2\Observer\DataAssignObserver;
use CheckoutCom\Magento2\Gateway\Config\Config as GatewayConfig;
use CheckoutCom\Magento2\Gateway\Http\TransferFactory;
use CheckoutCom\Magento2\Api\MobilePaymentInterface;

/**
* Defines the implementaton class of the charge through API.
*/
class MobilePayment implements MobilePaymentInterface
{

/**
* @var GatewayConfig
*/
Expand All @@ -44,13 +42,44 @@ class MobilePayment implements MobilePaymentInterface
*/
protected $transferFactory;

/**
* @var CustomerRepositoryInterface
*/
protected $customerRepository;

/**
* @var Product
*/
protected $productManager;

/**
* @var Array
*/
protected $data;

/**
* @var String
*/
protected $customer;

/**
* @var QuoteFactory
*/
protected $quoteFactory;

/**
* @var StoreManagerInterface
*/
protected $storeManager;

/**
* @var OrderService
*/
protected $orderService;

/**
* @var Address
*/
protected $addressManager;

/**
Expand Down
32 changes: 26 additions & 6 deletions Model/Service/CallbackService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use CheckoutCom\Magento2\Model\Method\CallbackMethod;
use CheckoutCom\Magento2\Gateway\Config\Config as GatewayConfig;
use CheckoutCom\Magento2\Model\Service\StoreCardService;
use CheckoutCom\Magento2\Model\Service\OrderService;

class CallbackService {

Expand Down Expand Up @@ -89,6 +90,11 @@ class CallbackService {
*/
protected $orderSender;

/**
* @var OrderService
*/
protected $orderService;

/**
* CallbackService constructor.
* @param CallbackMethod $callbackMethod
Expand All @@ -107,7 +113,8 @@ public function __construct(
StoreCardService $storeCardService,
CustomerFactory $customerFactory,
StoreManagerInterface $storeManager,
OrderSender $orderSender
OrderSender $orderSender,
OrderService $orderService
) {
$this->callbackMethod = $callbackMethod;
$this->eventAdapter = $eventAdapter;
Expand All @@ -120,6 +127,7 @@ public function __construct(
$this->customerFactory = $customerFactory;
$this->storeManager = $storeManager;
$this->orderSender = $orderSender;
$this->orderService = $orderService;
}

/**
Expand Down Expand Up @@ -153,12 +161,10 @@ public function run() {
$this->putGatewayResponseToHolder();

// Test the command name
if ($commandName == 'refund') {
$this->callbackMethod->refund($payment, $amount);
}
else if ($commandName == 'void') {
$this->callbackMethod->void($payment);
if ($commandName == 'refund' || $commandName == 'void') {
$this->orderService->cancelTransactionFromRemote($order);
}

// Perform authorize complementary actions
else if ($commandName == 'authorize') {
// Update order status
Expand Down Expand Up @@ -190,6 +196,20 @@ public function run() {
// Update order status
$order->setStatus($this->gatewayConfig->getOrderStatusCaptured());

// Create the invoice
if ($order->canInvoice() && ($this->gatewayConfig->getAutoGenerateInvoice())) {
$amount = ChargeAmountAdapter::getStoreAmountOfCurrency(
$this->gatewayResponse['response']['message']['value'],
$this->gatewayResponse['response']['message']['currency']
);
$invoice = $this->invoiceService->prepareInvoice($order);
$invoice->setRequestedCaptureCase(Invoice::CAPTURE_ONLINE);
$invoice->setBaseGrandTotal($amount);
$invoice->register();

$this->invoiceRepository->save($invoice);
}

// Comments override
if ($overrideComments) {
// Create new comment
Expand Down
Loading

0 comments on commit 98e1888

Please sign in to comment.