Skip to content

Commit

Permalink
PLGMAG2V2-729: Refactor support for Payment Components, Apple Pay and…
Browse files Browse the repository at this point in the history
… Google Pay, removing multisafepayPaymentComponentData query, and adding multisafepayPaymentRequestData query (#57)
  • Loading branch information
vinodsowdagar committed Apr 9, 2024
1 parent 1fc0836 commit ea14654
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 89 deletions.
81 changes: 7 additions & 74 deletions Model/Resolver/PaymentComponentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Quote\Model\MaskedQuoteIdToQuoteId;
use MultiSafepay\ConnectCore\Model\Ui\GenericConfigProvider;
use MultiSafepay\ConnectCore\CustomerData\PaymentRequest;
use Magento\Checkout\Model\Session as CheckoutSession;
use MultiSafepay\ConnectCore\Config\Config;
use Magento\Framework\Locale\ResolverInterface as LocaleResolverInterface;
use MultiSafepay\ConnectGraphQl\Model\PaymentConfig;

class PaymentComponentData implements ResolverInterface
{
Expand All @@ -42,47 +39,23 @@ class PaymentComponentData implements ResolverInterface
private $maskedQuoteIdToQuoteId;

/**
* @var Config
* @var PaymentRequest
*/
private $config;

/**
* @var LocaleResolverInterface
*/
private $localeResolver;

/**
* @var GenericConfigProvider
*/
private $genericConfigProvider;

/**
* @var PaymentConfig
*/
private $paymentConfig;
private $paymentRequest;

/**
* @param CheckoutSession $checkoutSession
* @param MaskedQuoteIdToQuoteId $maskedQuoteIdToQuoteId
* @param Config $config
* @param LocaleResolverInterface $localeResolver
* @param GenericConfigProvider $genericConfigProvider
* @param PaymentConfig $paymentConfig
* @param PaymentRequest $paymentRequest
*/
public function __construct(
CheckoutSession $checkoutSession,
MaskedQuoteIdToQuoteId $maskedQuoteIdToQuoteId,
Config $config,
LocaleResolverInterface $localeResolver,
GenericConfigProvider $genericConfigProvider,
PaymentConfig $paymentConfig
PaymentRequest $paymentRequest
) {
$this->checkoutSession = $checkoutSession;
$this->maskedQuoteIdToQuoteId = $maskedQuoteIdToQuoteId;
$this->config = $config;
$this->localeResolver = $localeResolver;
$this->genericConfigProvider = $genericConfigProvider;
$this->paymentConfig = $paymentConfig;
$this->paymentRequest = $paymentRequest;
}

/**
Expand All @@ -104,46 +77,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
$maskedCartId = $args['cart_id'];
$cartId = $this->maskedQuoteIdToQuoteId->execute($maskedCartId);
$this->checkoutSession->setQuoteId($cartId);
$sectionData = $this->getSectionData();

return $sectionData;
}

/**
* @return array|false[]
*
* @throws LocalizedException
* @throws NoSuchEntityException
*/
private function getSectionData(): array
{
try {
$quote = $this->checkoutSession->getQuote();
$storeId = (int) $quote->getStoreId();
$result = [
"enabled" => false,
"environment" => $this->config->isLiveMode($storeId) ? 'live' : 'test',
"locale" => $this->localeResolver->getLocale(),
"cartTotal" => $quote->getGrandTotal(),
"currency" => $this->paymentConfig->getCurrency(),
];

if ($cardsConfig = $this->paymentConfig->getCardsConfig($storeId)) {
$result = array_merge(
$result,
[
"enabled" => true,
"cardsConfig" => $cardsConfig,
'apiToken' => $this->genericConfigProvider->getApiToken($storeId)
]
);
}
$result['isDebug'] = $this->config->isDebug($storeId);
} catch (Exception $exception) {
$this->logger->logPaymentRequestGetCustomerDataException($exception);
$result = $result ?? ["enabled" => false];
}

return $result;
return $this->paymentRequest->getSectionData();
}
}
88 changes: 87 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ query {
}
}
```
- setPaymentMethodOnCart query example:
- setPaymentMethodOnCart query with issuers example:
```graphql
mutation {
setPaymentMethodOnCart(input: {
Expand All @@ -97,6 +97,92 @@ mutation {
}
}
```
- To retrieve MultiSafepay request data which includes information about Payment Component, Apple Pay or/and Google Pay, you can use the following query:
```graphql
query MultisafepayPaymentRequestData {
multisafepayPaymentRequestData(cart_id: { CART_ID }) {
apiToken
apiTokenLifeTime
cartTotal
currency
environment
locale
paymentComponentContainerId
payment_component_template_id
storeId
applePayButton {
applePayButtonId
getMerchantSessionUrl
isActive
additionalTotalItems {
amount
label
}
cartItems {
label
price
}
}
googlePayButton {
accountId
googlePayButtonId
isActive
mode
merchantInfo {
merchantId
merchantName
}
}
paymentComponentConfig {
gatewayCode
paymentMethod
paymentType
additionalInfo {
image
is_preselected
vaultCode
}
tokens {
bin
code
display
expired
expiry_date
last4
model
name_holder
token
}
}
}
}
```

- setPaymentMethodOnCart query with payment component payload example: (for more information on how to retrieve the payload, see the [MultiSafepay documentation](https://docs.multisafepay.com/docs/payment-component-single/))
```graphql
mutation {
setPaymentMethodOnCart(input: {
cart_id: "{ CART_ID }"
payment_method: {
code: "multisafepay_creditcard"
multisafepay_creditcard: {
payload: "xxxx"
tokenize: true
}
}
}) {
cart {
selected_payment_method {
code
multisafepay_additional_data {
image
is_preselected
}
}
}
}
}
```
- Place order request example. After placing the order, you will receive the `multisafepay_payment_url` on which the customer should be redirected to for placing a transaction:
```graphql
mutation {
Expand Down
77 changes: 63 additions & 14 deletions etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Mutation {

type Query {
multisafepayCart(cart_id: String!): Cart @resolver (class: "MultiSafepay\\ConnectGraphQl\\Model\\Resolver\\MultisafepayCart") @doc(description:"Returns information about shopping cart") @cache(cacheable: false)
multisafepayPaymentComponentData(cart_id: String!): MultisafepayPaymentDataOutput @resolver(class: "MultiSafepay\\ConnectGraphQl\\Model\\Resolver\\PaymentComponentData") @cache(cacheable: false)
multisafepayPaymentRequestData(cart_id: String!): MultisafepayPaymentRequestDataOutput @resolver(class: "MultiSafepay\\ConnectGraphQl\\Model\\Resolver\\PaymentComponentData") @cache(cacheable: false)
}

type Order {
Expand Down Expand Up @@ -130,37 +130,86 @@ input PlaceOrderInput @doc(description: "Specifies the quote to be converted to

input MultisafepayPaymentComponentInput @doc(description:"Required input for Payment Component") {
payload: String! @doc(description:"Payload")
tokenize: Boolean! @doc(description:"Tokenization enabled")
}

type CardTypes
{
type: String
}

type AdditionalInfo
type MultiSafepayPaymentComponentAdditionalInfo
{
vaultCode: String
image: String
is_preselected: Boolean
}

type CardsConfig
type MultiSafepayToken
{
token: String
code: String
display: String
bin: Int
name_holder: String
expiry_date: Int
expired: Boolean
last4: Int
model: String
}

type MultiSafepayPaymentComponentConfig
{
paymentMethod: String
gatewayCode: String
paymentType: String
customerReference: Int
additionalInfo: AdditionalInfo
tokens: [MultiSafepayToken]
additionalInfo: MultiSafepayPaymentComponentAdditionalInfo
}

type MultiSafepayApplePayButton
{
isActive: Boolean
applePayButtonId: String
getMerchantSessionUrl: String
cartItems: [MultiSafepayApplePayCartItem]
additionalTotalItems: [MultiSafepayApplePayAdditionalTotalItem]
}

type MultiSafepayGooglePayButton
{
isActive: Boolean
googlePayButtonId: String
mode: String
accountId: String
merchantInfo: MultiSafepayMerchantInfo
}

type MultiSafepayApplePayCartItem
{
label: String
price: Float
}

type MultiSafepayApplePayAdditionalTotalItem
{
label: String
amount: String
}

type MultiSafepayMerchantInfo
{
merchantName: String
merchantId: String
}

type MultisafepayPaymentDataOutput
type MultisafepayPaymentRequestDataOutput
{
enabled: Boolean
environment: String
locale: String
cartTotal: Float
currency: String
cardsConfig: [CardsConfig]
storeId: Int
payment_component_template_id: String
paymentComponentContainerId: String
paymentComponentConfig: [MultiSafepayPaymentComponentConfig]
apiToken: String
isDebug: Boolean
apiTokenLifeTime: Int
applePayButton: MultiSafepayApplePayButton
googlePayButton: MultiSafepayGooglePayButton
}

0 comments on commit ea14654

Please sign in to comment.