Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vipps method #2469

Closed
wants to merge 4 commits into from
Closed
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
81 changes: 81 additions & 0 deletions Model/Resolver/SaveAdyenStateData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
*
* Adyen Payment Module
*
* Copyright (c) 2023 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <[email protected]>
*/
declare(strict_types=1);

namespace Adyen\Payment\Model\Resolver;

use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
use Adyen\Payment\Api\AdyenStateDataInterface;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;

class SaveAdyenStateData
{

/**
* @var GetCartForUser
*/
protected GetCartForUser $cartForUser;

/**
* @var AdyenStateDataInterface
*/
protected AdyenStateDataInterface $stateData;

/**
* SaveAdyenStateData Constructor
*
* @param GetCartForUser $cartForUser
* @param AdyenStateDataInterface $stateData
*/
public function __construct(
GetCartForUser $cartForUser,
AdyenStateDataInterface $stateData
) {
$this->cartForUser = $cartForUser;
$this->stateData = $stateData;
}

/**
* @inheritDoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) {

$cartId = $args['cart_id'] ?? null;
if (!$cartId) {
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
}

$stateData = $args['state_data'] ?? null;
if (!$stateData) {
throw new GraphQlInputException('state_data');
}

$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
$cart = $this->cartForUser->execute($cartId, $context->getUserId(), $storeId);
$this->stateData->save($stateData, (int)$cart->getId());

return [
'cart' => [
'model' => $cart,
],
];
}
}
8 changes: 8 additions & 0 deletions etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ type Mutation {
payload: String! @doc(description: "Payload JSON String with orderId, details, paymentData and threeDSAuthenticationOnly.")
cart_id: String! @doc(description: "Cart ID.")
) : AdyenPaymentStatus @resolver(class: "Adyen\\Payment\\Model\\Resolver\\GetAdyenPaymentDetails")
adyenSaveStateData (
cart_id: String! @doc(description: "Cart ID.")
state_data: String! @doc(description: "JSON string with the payment state data, e.g. generated by the Adyen Web Components.")
) : AdyenSaveSateDataOutput @resolver(class: "Adyen\\Payment\\Model\\Resolver\\SaveAdyenStateData")@doc(description: "Persist the Adyen state data for the quote so it can be used in the payment request.")
}

type AdyenPaymentStatus {
Expand All @@ -25,6 +29,10 @@ type AdyenPaymentStatus {
action: String @doc(description: "Object containing information about the payment's next step.")
}

type AdyenSaveSateDataOutput {
cart: Cart!
}

type AdyenPaymentMethods {
paymentMethodsResponse: AdyenPaymentMethodsResponse @doc(description: "API response from Adyen with payment methods.")
paymentMethodsExtraDetails: [AdyenPaymentMethodsExtraDetails] @doc(description: "Payment method's additional details.")
Expand Down
Loading