Skip to content

Commit

Permalink
Init magento 2 GraphQL repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois-Gomis authored Feb 6, 2022
0 parents commit f9c0f85
Show file tree
Hide file tree
Showing 8 changed files with 348 additions and 0 deletions.
17 changes: 17 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
The MIT License

Further resources on the MIT License
Copyright 2018 Nabla SAS / Alma

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
57 changes: 57 additions & 0 deletions Model/Resolver/AlmaConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
namespace Alma\GraphQL\Model\Resolver;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Alma\MonthlyPayments\Helpers\Logger;
use Alma\MonthlyPayments\Gateway\Config\Config;


class AlmaConfig implements ResolverInterface
{
/**
* @var Logger
*/
private Logger $logger;
/**
* @var Config
*/
private Config $almaConfig;

public function __construct(
Logger $logger,
Config $almaConfig
) {
$this->logger = $logger;
$this->almaConfig = $almaConfig;
}

/**
* @param Field $field
* @param \Magento\Framework\GraphQl\Query\Resolver\ContextInterface $context
* @param ResolveInfo $info
* @param array|null $value
* @param array|null $args
* @return array|\Magento\Framework\GraphQl\Query\Resolver\Value|mixed
* @throws GraphQlInputException
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) {
$almaConfig = $value['model'];
return [
'model'=> $almaConfig,
'is_enable' => $this->almaConfig->getIsActive(),
'mode' => $this->almaConfig->getActiveMode(),
'title' => $this->almaConfig->getPaymentButtonTitle(),
'description' => $this->almaConfig->getPaymentButtonDescription(),
'sort_order' => $this->almaConfig->getSortOrder(),
];
}
}
82 changes: 82 additions & 0 deletions Model/Resolver/AlmaFeePlans.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
namespace Alma\GraphQL\Model\Resolver;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Alma\MonthlyPayments\Helpers\Logger;
use Alma\MonthlyPayments\Helpers\Eligibility;

class AlmaFeePlans implements ResolverInterface
{
public function __construct(
Logger $logger,
Eligibility $eligibility
) {
$this->logger = $logger;
$this->eligibility = $eligibility;
}

/**
* @param Field $field
* @param \Magento\Framework\GraphQl\Query\Resolver\ContextInterface $context
* @param ResolveInfo $info
* @param array|null $value
* @param array|null $args
* @return array|\Magento\Framework\GraphQl\Query\Resolver\Value|mixed
* @throws GraphQlInputException
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) {
$almaEligibility = $value['model'];
$paymentPlans = [];
$feePlans = $this->getFeePlans();
foreach ($feePlans as $key=> $plan){
$planConfig = $plan->getPlanConfig()->toArray();
$planEligibility = $plan->getEligibility();
$paymentPlans[$key]['key'] = $planConfig['key'];
$paymentPlans[$key]['logo'] = $planConfig['logo'];
$paymentPlans[$key]['allowed'] = $planConfig['allowed'];
$paymentPlans[$key]['kind'] = $planConfig['kind'];
$paymentPlans[$key]['installments_count'] = $planConfig['installmentsCount'];
$paymentPlans[$key]['deferred_days'] = $planConfig['deferredDays'];
$paymentPlans[$key]['deferred_months'] = $planConfig['deferredMonths'];
$paymentPlans[$key]['enabled'] = $planConfig['enabled'];
$paymentPlans[$key]['min_amount'] = $planConfig['minAmount'];
$paymentPlans[$key]['max_amount'] = $planConfig['maxAmount'];
$paymentPlans[$key]['customer_lending_rate'] = $planConfig['customerLendingRate'];
$paymentPlans[$key]['deferred_type'] = $planConfig['deferredType'];
$paymentPlans[$key]['deferred_duration'] = $planConfig['deferredDuration'];
$paymentPlans[$key]['eligibility']['is_eligible'] = $planEligibility->isEligible;
$paymentPlans[$key]['eligibility']['reasons'] = $planEligibility->reasons;
$paymentPlans[$key]['eligibility']['constraints'] = $planEligibility->constraints;
foreach ($planEligibility->paymentPlan as $feePlan){
$paymentPlans[$key]['eligibility']['fee_plans'][] =$feePlan;
}
}
return array_values($paymentPlans);
}

/**
* Get fee plans
*
* @return array
*/
private function getFeePlans(): array
{
$this->logger->info('get Alma Fee plans in Graph QL resolver',[]);
$plans = $this->eligibility->getCurrentsFeePlans();
if (!$this->eligibility->isAlreadyLoaded()){
$plans=$this->eligibility->getEligiblePlans();
}
return $plans;
}
}
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Alma Monthly Payments for Magento 2 GraphQL
===========================================

This plugin adds a new payment method to Magento 2 GraphQL API, which allows you to offer monthly payments to your customer using Alma.

## ⚠️ Restricted availability

🇫🇷Pour le moment, Alma n'est disponible qu'aux marchands **français** avec lesquels nous pouvons interagir. Vous pouvez [créer votre compte](https://dashboard.getalma.eu) librement, mais devez nous contacter pour l'activer et commencer à accepter des paiements.

🇬🇧For the moment, Alma is only available to **french** merchants with whom we can communicate. You can [create your account](https://dashboard.getalma.eu) freely, but you must contact us to have it activated and to start accepting payments.


## Description

[Alma](https://getalma.eu) is a service to provide merchants with an **easy** and **safe** monthly payments solution.
Let your customers pay for their purchases at their own pace! You'll receive the funds instantly, and your customer will pay later over a few monthly instalments.

This plugin integrates Alma into Magento 2 by adding a new payment method that you can activate to offer monthly payments to your customers.

## Installation

### Prerequisites

You first need to create your merchant account on [dashboard.getalma.eu](https://dashboard.getalma.eu) and activate your account.

### Installing

#### Using Composer
The easiest way to install the extension is to use Composer:

```bash
$ composer require alma/magento2-graphql
$ bin/magento module:enable Alma_MonthlyPayments
$ bin/magento module:enable Alma_GraphQL
$ bin/magento setup:upgrade && bin/magento setup:static-content:deploy
```

### Configuring the plugin

After installing the plugin, go to `Stores > Configuration > Sales > Payment Methods`.
Find "Alma Monthly Payments" in the payment methods list to start configuring it.

Fill in the API keys for your account, which you can find on your dashboard\'s [security page](https://dashboard.getalma.eu/security).

You also have access to different settings to control what the plugin should display on the Cart, Mini-cart and Checkout pages.
We advise you to stay in \"Test\" mode until you\'re happy with your configuration and are ready to accept payments from your customers.

Once everything is properly set up, go ahead and switch to \"Live\" mode!
34 changes: 34 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "alma/magento2-graphql",
"description": "Integrates Alma Monthly Payments into Graph QL Magento 2 ",
"require": {
"php": ">=5.5",
"alma/alma-monthlypayments-magento2": ">=2.0.0"
},
"type": "magento2-module",
"version": "0.1.0",
"license": [
"MIT"
],
"autoload": {
"files": [ "registration.php" ],
"psr-4": {
"Alma\\GraphQL\\": ""
}
},
"repositories": [
{
"type": "composer",
"url": "https://repo.magento.com/"
}
],
"require-dev": {
"magento/module-sales": ">=100.0.2",
"magento/module-csp": ">=100.0.2",
"magento/module-checkout": ">=100.0.2",
"magento/module-payment": ">=100.0.2",
"magento/framework": ">=100.0.2",
"magento/magento-composer-installer": "*",
"magento/module-sample-data": "^100.4"
}
}
35 changes: 35 additions & 0 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<!--
/**
* 2018 Alma / Nabla SAS
*
* THE MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @author Alma / Nabla SAS <[email protected]>
* @copyright 2018 Alma / Nabla SAS
* @license https://opensource.org/licenses/MIT The MIT License
*
*/
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Alma_GraphQL" setup_version="0.1.0">
<sequence>
<module name="Alma_MonthlyPayments"/>
</sequence>
</module>
</config>
46 changes: 46 additions & 0 deletions etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#Custom Module
extend type Cart {
alma: AlmaInput @resolver(class: "Alma\\GraphQL\\Model\\Resolver\\AlmaConfig") @doc(description:"Resolve alma defaul config")
}

type AlmaEligibility {
is_eligible:Boolean
reasons: String
constraints: String
fee_plans: [Instalment]
}

type Instalment {
customer_fee: Int
customer_interest: Int
due_date: Int
purchase_amount: Int
refunded_interest: Int
total_amount: Int
}

type AlmaInput {
is_enable: String @doc(description: "Back Office Enable")
mode: String @doc(description: "Back Office Active mode - Production or Test")
title: String @doc(description: "Back Office Title")
description: String @doc(description: "Back office desciption")
sort_order: String @doc(description: "Back Office Sort Order")
fee_plans: [AlmaFeePlans] @resolver(class: "Alma\\GraphQL\\Model\\Resolver\\AlmaFeePlans") @doc(description:"Resolve Alma Fee Plans")
}

type AlmaFeePlans {
allowed: Boolean @doc(description: "Is Allowed by Alma")
enabled: Boolean @doc(description: "Is enabled in Bo")
kind: String @doc(description: "Payment plan aera")
deferred_type: String @doc(description: "Deferred type")
deferred_duration: String @doc(description: "Deferred duration")
installments_count: Int @doc(description: "Number of Installment")
deferred_days: Int @doc(description: "Number of payment deferred Days")
deferred_months: Int @doc(description: "Number of paymenbt deferred month")
min_amount: Int @doc(description: "Min purchase amount in cent")
max_amount: Int @doc(description: "Max purchase amount in cent")
customer_lending_rate: Int @doc(description: "Customer credit cost")
logo: String @doc(description: "Fee plan logo")
key: String @doc(description: "Fee plan Key for Additional data")
eligibility: AlmaEligibility @doc(description:"Resolve Alma Fee Plans")
}
29 changes: 29 additions & 0 deletions registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* 2018 Alma / Nabla SAS
*
* THE MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @author Alma / Nabla SAS <[email protected]>
* @copyright 2018 Alma / Nabla SAS
* @license https://opensource.org/licenses/MIT The MIT License
*
*/

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Alma_GraphQL', __DIR__);

0 comments on commit f9c0f85

Please sign in to comment.