Skip to content

Commit

Permalink
Merge pull request #24 from logeecom/master
Browse files Browse the repository at this point in the history
PISYL-247: PISYL-245: Add Riverty and trusty payment methods
  • Loading branch information
hwysoszynski authored Jul 29, 2024
2 parents e11165b + 65b5a3c commit 1bf21d1
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"php": "^7.4 || ^8.0",
"sylius/sylius": "~1.9.0 || ~1.10.0 || ~1.11.0 || ~1.12.0",
"symfony/messenger": "^4.4 || ^5.2 || ^6.0",
"mollie/mollie-api-php": "^v2.65.0",
"mollie/mollie-api-php": "^v2.71.0",
"sylius/refund-plugin": "^1.0",
"sylius/admin-order-creation-plugin": "^0.12 || ^0.13 || v0.14",
"ext-json": "*",
Expand Down
2 changes: 1 addition & 1 deletion src/Action/CaptureAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function execute($request): void
));
}

$this->gateway->execute(new CreatePayment($details));
$this->gateway->execute(new CreateOrder($details));
}

if (isset($details['metadata']['methodType']) && Options::ORDER_API === $details['metadata']['methodType']) {
Expand Down
15 changes: 11 additions & 4 deletions src/Helper/ConvertOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace SyliusMolliePlugin\Helper;

use Mollie\Api\Types\PaymentMethod;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Core\Model\Scope;
use Sylius\Component\Core\Model\ShippingMethodInterface;
Expand Down Expand Up @@ -84,7 +85,7 @@ public function convert(
$details['amount']['value'] = $amount;
$details['orderNumber'] = (string) $order->getNumber();
$details['shippingAddress'] = $this->createShippingAddress($customer);
$details['billingAddress'] = $this->createBillingAddress($customer);
$details['billingAddress'] = $this->createBillingAddress($customer, $method->getMethodId());
$details['lines'] = $this->createLines($divisor, $method);
$details['lines'] = array_merge($details['lines'], $this->createShippingFee($divisor));

Expand All @@ -109,22 +110,28 @@ private function createShippingAddress(CustomerInterface $customer): array
];
}

private function createBillingAddress(CustomerInterface $customer): array
private function createBillingAddress(CustomerInterface $customer, string $methodId): array
{
$billingAddress = $this->order->getBillingAddress();

Assert::notNull($billingAddress);

return [
$address = [
'streetAndNumber' => $billingAddress->getStreet(),
'postalCode' => $billingAddress->getPostcode(),
'city' => $billingAddress->getCity(),
'country' => $billingAddress->getCountryCode(),
'givenName' => $billingAddress->getFirstName(),
'familyName' => $billingAddress->getLastName(),
'organizationName' => $billingAddress->getCompany(),
'email' => $customer->getEmail(),
'email' => $customer->getEmail()
];

if ($methodId === PaymentMethod::BANCOMATPAY && $billingAddress->getPhoneNumber()) {
$address['phone'] = $billingAddress->getPhoneNumber();
}

return $address;
}

private function createLines(int $divisor, MollieGatewayConfigInterface $method): array
Expand Down
2 changes: 1 addition & 1 deletion src/Migrations/Version20240301074755.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getDescription(): string

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE ' . self::TABLE_NAME . ' ADD qr_code_enabled TINYINT(1) NOT NULL');
$this->addSql('ALTER TABLE ' . self::TABLE_NAME . ' ADD qr_code_enabled TINYINT(1) DEFAULT NULL');
}

public function down(Schema $schema): void
Expand Down
32 changes: 32 additions & 0 deletions src/Migrations/Version20240627164350.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace SyliusMolliePlugin\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

class Version20240627164350 extends AbstractMigration
{
//table name
private const TABLE_NAME = 'mollie_configuration';

public function getDescription(): string
{
return '';
}

/**
* Delete giropay payment method from mollie configuration table
*
* @param Schema $schema
* @return void
*/
public function up(Schema $schema): void
{
$this->addSql('DELETE FROM ' . self::TABLE_NAME . ' WHERE method_id = \'giropay\'');
}

public function down(Schema $schema): void
{
}
}
39 changes: 39 additions & 0 deletions src/Migrations/Version20240716134351.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace SyliusMolliePlugin\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

class Version20240716134351 extends AbstractMigration
{
private const TABLE_NAME = 'mollie_configuration';

/**
* @return string
*/
public function getDescription(): string
{
return 'Change qr_code_enabled column to allow NULL values and set default to NULL';
}

/**
* @param Schema $schema
*
* @return void
*/
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE ' . self::TABLE_NAME . ' MODIFY qr_code_enabled TINYINT(1) DEFAULT NULL');
}

/**
* @param Schema $schema
*
* @return void
*/
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE ' . self::TABLE_NAME . ' MODIFY qr_code_enabled TINYINT(1) NOT NULL');
}
}
18 changes: 18 additions & 0 deletions src/Payments/Methods/Bancomatpay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace SyliusMolliePlugin\Payments\Methods;

use Mollie\Api\Types\PaymentMethod;

final class Bancomatpay extends AbstractMethod
{
public function getMethodId(): string
{
return PaymentMethod::BANCOMATPAY;
}

public function getPaymentType(): string
{
return self::PAYMENT_API;
}
}
17 changes: 17 additions & 0 deletions src/Payments/Methods/Payconiq.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace SyliusMolliePlugin\Payments\Methods;

use Mollie\Api\Types\PaymentMethod;

final class Payconiq extends AbstractMethod
{
public function getMethodId(): string
{
return PaymentMethod::PAYCONIQ;
}
public function getPaymentType(): string
{
return self::PAYMENT_API;
}
}
17 changes: 17 additions & 0 deletions src/Payments/Methods/Riverty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace SyliusMolliePlugin\Payments\Methods;

use Mollie\Api\Types\PaymentMethod;

final class Riverty extends AbstractMethod
{
public function getMethodId(): string
{
return PaymentMethod::RIVERTY;
}
public function getPaymentType(): string
{
return self::ORDER_API;
}
}
18 changes: 18 additions & 0 deletions src/Payments/Methods/Trustly.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace SyliusMolliePlugin\Payments\Methods;

use Mollie\Api\Types\PaymentMethod;

class Trustly extends AbstractMethod
{
public function getMethodId(): string
{
return 'trustly';
}

public function getPaymentType(): string
{
return self::PAYMENT_API;
}
}
10 changes: 8 additions & 2 deletions src/Payments/MethodsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use SyliusMolliePlugin\Payments\Methods\Alma;
use SyliusMolliePlugin\Payments\Methods\ApplePay;
use SyliusMolliePlugin\Payments\Methods\Bancomatpay;
use SyliusMolliePlugin\Payments\Methods\Bancontact;
use SyliusMolliePlugin\Payments\Methods\BankTransfer;
use SyliusMolliePlugin\Payments\Methods\Belfius;
Expand All @@ -16,7 +17,6 @@
use SyliusMolliePlugin\Payments\Methods\DirectDebit;
use SyliusMolliePlugin\Payments\Methods\Eps;
use SyliusMolliePlugin\Payments\Methods\GiftCard;
use SyliusMolliePlugin\Payments\Methods\Giropay;
use SyliusMolliePlugin\Payments\Methods\Ideal;
use SyliusMolliePlugin\Payments\Methods\In3;
use SyliusMolliePlugin\Payments\Methods\Kbc;
Expand All @@ -26,10 +26,13 @@
use SyliusMolliePlugin\Payments\Methods\Klarnasliceit;
use SyliusMolliePlugin\Payments\Methods\MealVoucher;
use SyliusMolliePlugin\Payments\Methods\MyBank;
use SyliusMolliePlugin\Payments\Methods\Payconiq;
use SyliusMolliePlugin\Payments\Methods\PayPal;
use SyliusMolliePlugin\Payments\Methods\Przelewy24;
use SyliusMolliePlugin\Payments\Methods\Riverty;
use SyliusMolliePlugin\Payments\Methods\SofortBanking;
use Mollie\Api\Resources\Method;
use SyliusMolliePlugin\Payments\Methods\Trustly;
use SyliusMolliePlugin\Payments\Methods\Twint;

interface MethodsInterface
Expand All @@ -43,7 +46,6 @@ interface MethodsInterface
CreditCard::class,
Eps::class,
GiftCard::class,
Giropay::class,
Ideal::class,
Kbc::class,
KlarnaOne::class,
Expand All @@ -60,6 +62,10 @@ interface MethodsInterface
Billie::class,
Twint::class,
Blik::class,
Riverty::class,
Trustly::class,
Bancomatpay::class,
Payconiq::class
];

public function getAllEnabled(): array;
Expand Down
1 change: 1 addition & 0 deletions src/Payments/PaymentTerms/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static function getOnlyOrderAPIMethods(): array
PaymentMethod::IN3,
PaymentMethod::BILLIE,
MealVoucher::MEAL_VOUCHERS,
PaymentMethod::RIVERTY
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{% set billie = constant('Mollie\\Api\\Types\\PaymentMethod::BILLIE') %}
{% set in3 = constant('Mollie\\Api\\Types\\PaymentMethod::IN3') %}
{% set alma = constant('Mollie\\Api\\Types\\PaymentMethod::ALMA') %}
{% set riverty = constant('Mollie\\Api\\Types\\PaymentMethod::RIVERTY') %}
{% import '@SyliusUi/Macro/flags.html.twig' as flags %}

<div class="ui segment" id="mollie-payment-form" data-status="{{resource.id}}">
Expand Down Expand Up @@ -142,6 +143,7 @@
methodForm.vars.value.methodId == klarnaSliceIt or
methodForm.vars.value.methodId == billie or
methodForm.vars.value.methodId == alma or
methodForm.vars.value.methodId == riverty or
methodForm.vars.value.methodId == in3
%}
{{ form_row(methodForm.paymentType, {'attr': {'disabled': 'disabled', 'class': 'js-onboardingWizard-PaymentMethod'}}) }}
Expand Down

0 comments on commit 1bf21d1

Please sign in to comment.