Skip to content

Commit

Permalink
feat: use guest payment information on guest checkout (#57)
Browse files Browse the repository at this point in the history
Co-authored-by: Khushboo <[email protected]>
Co-authored-by: Can Demiralp <[email protected]>
  • Loading branch information
3 people authored Nov 8, 2024
1 parent 11e6f49 commit 4b0a5b4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
25 changes: 21 additions & 4 deletions Magewire/Payment/Method/AdyenPaymentComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
use Hyva\Checkout\Model\Magewire\Component\Evaluation\EvaluationResult;
use Hyva\Checkout\Model\Magewire\Component\EvaluationInterface;
use Hyva\Checkout\Model\Magewire\Component\EvaluationResultFactory;
use Magento\Checkout\Api\GuestPaymentInformationManagementInterface;
use Magento\Checkout\Api\PaymentInformationManagementInterface;
use Magento\Checkout\Model\Session;
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
use Magewirephp\Magewire\Component;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -49,6 +51,8 @@ abstract class AdyenPaymentComponent extends Component implements EvaluationInte
protected StateData $stateData;
protected PaymentMethods $paymentMethods;
protected PaymentInformationManagementInterface $paymentInformationManagement;
protected GuestPaymentInformationManagementInterface $guestPaymentInformationManagement;
protected QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId;
protected AdyenOrderPaymentStatusInterface $adyenOrderPaymentStatus;
protected AdyenPaymentsDetailsInterface $adyenPaymentsDetails;
protected CustomerGroupHandler $customerGroupHandler;
Expand All @@ -65,6 +69,8 @@ public function __construct(
$this->stateData = $context->getStateData();
$this->paymentMethods = $context->getPaymentMethods();
$this->paymentInformationManagement = $context->getPaymentInformationManagement();
$this->guestPaymentInformationManagement = $context->getGuestPaymentInformationManagement();
$this->quoteIdToMaskedQuoteId = $this->context->getQuoteIdToMaskedQuoteId();
$this->adyenOrderPaymentStatus = $context->getAdyenOrderPaymentStatus();
$this->adyenPaymentsDetails = $context->getAdyenPaymentsDetails();
$this->customerGroupHandler = $context->getCustomerGroupHandler();
Expand Down Expand Up @@ -100,10 +106,21 @@ public function placeOrder(array $data): void
$stateDataReceived = $this->collectValidatedStateData($data);
//Temporary (per request) storage of state data
$this->stateData->setStateData($stateDataReceived, (int) $quoteId);
$orderId = $this->paymentInformationManagement->savePaymentInformationAndPlaceOrder(
$quoteId,
$payment
);

if ($this->userIsGuest()) {
$email = $this->session->getQuote()->getCustomerEmail();
$maskedQuoteId = $this->quoteIdToMaskedQuoteId->execute((int) $quoteId);
$orderId = $this->guestPaymentInformationManagement->savePaymentInformationAndPlaceOrder(
$maskedQuoteId,
$email,
$payment
);
} else {
$orderId = $this->paymentInformationManagement->savePaymentInformationAndPlaceOrder(
$quoteId,
$payment
);
}
$this->paymentStatus = $this->adyenOrderPaymentStatus->getOrderPaymentStatus(strval($orderId));
} catch (\Exception $exception) {
$this->paymentStatus = json_encode(['isRefused' => true]);
Expand Down
20 changes: 20 additions & 0 deletions Model/Component/Payment/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
use Adyen\Payment\Api\AdyenPaymentsDetailsInterface;
use Adyen\Payment\Helper\StateData;
use Adyen\Payment\Helper\Util\CheckoutStateDataValidator;
use Magento\Checkout\Api\GuestPaymentInformationManagementInterface;
use Magento\Checkout\Api\PaymentInformationManagementInterface;
use Magento\Checkout\Model\Session;
use Magento\Framework\ObjectManager\ContextInterface;
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
use Psr\Log\LoggerInterface;

class Context implements ContextInterface
Expand All @@ -23,6 +25,8 @@ public function __construct(
private readonly StateData $stateData,
private readonly PaymentMethods $paymentMethods,
private readonly PaymentInformationManagementInterface $paymentInformationManagement,
private readonly GuestPaymentInformationManagementInterface $guestPaymentInformationManagement,
private readonly QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId,
private readonly AdyenOrderPaymentStatusInterface $adyenOrderPaymentStatus,
private readonly AdyenPaymentsDetailsInterface $adyenPaymentsDetails,
private readonly CustomerGroupHandler $customerGroupHandler,
Expand Down Expand Up @@ -78,6 +82,22 @@ public function getPaymentInformationManagement(): PaymentInformationManagementI
return $this->paymentInformationManagement;
}

/**
* @return PaymentInformationManagementInterface
*/
public function getGuestPaymentInformationManagement(): GuestPaymentInformationManagementInterface
{
return $this->guestPaymentInformationManagement;
}

/**
* @return QuoteIdToMaskedQuoteIdInterface
*/
public function getQuoteIdToMaskedQuoteId(): QuoteIdToMaskedQuoteIdInterface
{
return $this->quoteIdToMaskedQuoteId;
}

/**
* @return AdyenOrderPaymentStatusInterface
*/
Expand Down

0 comments on commit 4b0a5b4

Please sign in to comment.