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

PIPRES-352: Billie payment method #19

Merged
merged 3 commits into from
Nov 7, 2023
Merged
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
2 changes: 1 addition & 1 deletion src/Adapter/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function getModuleLink(
);
}

public function getAddressInvoiceId(): int
public function getInvoiceAddressId(): int
{
return (int) $this->getContext()->cart->id_address_invoice;
}
Expand Down
12 changes: 5 additions & 7 deletions src/Builder/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ protected function getAccountSettingsSection($isApiKeyProvided)
'customLogoUrl' => $this->creditCardLogoProvider->getLogoPathUri() . "?{$dateStamp}",
'customLogoExist' => $this->creditCardLogoProvider->logoExists(),
'voucherCategory' => $this->configurationAdapter->get(Config::MOLLIE_VOUCHER_CATEGORY),
'klarnaPayments' => Config::KLARNA_PAYMENTS,
'klarnaStatuses' => [Config::MOLLIE_STATUS_KLARNA_AUTHORIZED, Config::MOLLIE_STATUS_KLARNA_SHIPPED],
'applePayDirectProduct' => (int) $this->configurationAdapter->get(Config::MOLLIE_APPLE_PAY_DIRECT_PRODUCT),
'applePayDirectCart' => (int) $this->configurationAdapter->get(Config::MOLLIE_APPLE_PAY_DIRECT_CART),
'applePayDirectStyle' => (int) $this->configurationAdapter->get(Config::MOLLIE_APPLE_PAY_DIRECT_STYLE),
Expand Down Expand Up @@ -481,22 +479,22 @@ protected function getAdvancedSettingsSection()

$input[] = [
'type' => 'select',
'label' => $this->module->l('Select when to create the Klarna invoice', self::FILE_NAME),
'label' => $this->module->l('Select when to create the Order invoice', self::FILE_NAME),
'desc' => $this->module->display($this->module->getPathUri(), 'views/templates/admin/invoice_description.tpl'),
'tab' => $advancedSettings,
'name' => Config::MOLLIE_KLARNA_INVOICE_ON,
'name' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS,
'options' => [
'query' => [
[
'id' => Config::MOLLIE_STATUS_DEFAULT,
'id' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT,
'name' => $this->module->l('Default', self::FILE_NAME),
],
[
'id' => Config::MOLLIE_STATUS_KLARNA_AUTHORIZED,
'id' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED,
'name' => $this->module->l('Authorised', self::FILE_NAME),
],
[
'id' => Config::MOLLIE_STATUS_KLARNA_SHIPPED,
'id' => Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED,
'name' => $this->module->l('Shipped', self::FILE_NAME),
],
],
Expand Down
31 changes: 20 additions & 11 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ class Config
const MOLLIE_STATUS_INITIATED = 'MOLLIE_STATUS_INITIATED';
const MOLLIE_STATUS_PARTIALLY_SHIPPED = 'MOLLIE_PARTIALLY_SHIPPED';
const MOLLIE_STATUS_ORDER_COMPLETED = 'MOLLIE_STATUS_ORDER_COMPLETED';
const MOLLIE_STATUS_DEFAULT = 'MOLLIE_STATUS_DEFAULT';
const MOLLIE_STATUS_KLARNA_AUTHORIZED = 'MOLLIE_STATUS_KLARNA_AUTHORIZED';
const MOLLIE_STATUS_KLARNA_SHIPPED = 'MOLLIE_STATUS_KLARNA_SHIPPED';
const MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT = 'MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT';
const MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED = 'MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED';
const MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED = 'MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED';
const MOLLIE_STATUS_CHARGEBACK = 'MOLLIE_STATUS_CHARGEBACK';
const MOLLIE_KLARNA_INVOICE_ON = 'MOLLIE_KLARNA_INVOICE_ON';
const MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS = 'MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS';
const MOLLIE_APPLE_PAY_DIRECT_PRODUCT = 'MOLLIE_APPLE_PAY_DIRECT_PRODUCT';
const MOLLIE_APPLE_PAY_DIRECT_CART = 'MOLLIE_APPLE_PAY_DIRECT_CART';

Expand Down Expand Up @@ -239,6 +239,11 @@ class Config
const MOLLIE_VOUCHER_METHOD_ID = 'voucher';
const MOLLIE_in3_METHOD_ID = 'in3';

/**
* @see https://www.mollie.com/en/payments/billie
*/
const MOLLIE_PAYMENT_METHOD_BILLIE = 'billie';

const MOLLIE_VOUCHER_CATEGORY_NULL = 'null';
const MOLLIE_VOUCHER_CATEGORY_MEAL = 'meal';
const MOLLIE_VOUCHER_CATEGORY_GIFT = 'gift';
Expand All @@ -257,16 +262,18 @@ class Config
const RESTORE_CART_BACKTRACE_MEMORIZATION_SERVICE = 'memo';
const RESTORE_CART_BACKTRACE_RETURN_CONTROLLER = 'return';

const KLARNA_PAYMENTS = [
const AUTHORIZABLE_PAYMENTS = [
PaymentMethod::KLARNA_PAY_LATER,
PaymentMethod::KLARNA_SLICE_IT,
PaymentMethod::KLARNA_PAY_NOW,
self::MOLLIE_PAYMENT_METHOD_BILLIE,
];

const ORDER_API_ONLY_METHODS = [
PaymentMethod::KLARNA_PAY_LATER,
PaymentMethod::KLARNA_SLICE_IT,
PaymentMethod::KLARNA_PAY_NOW,
self::MOLLIE_PAYMENT_METHOD_BILLIE,
self::MOLLIE_VOUCHER_METHOD_ID,
self::MOLLIE_in3_METHOD_ID,
];
Expand Down Expand Up @@ -304,6 +311,7 @@ class Config
'voucher' => 'Voucher',
'klarnapaynow' => 'Klarna Pay now.',
'in3' => 'in3',
'billie' => 'Billie',
];

const MOLLIE_BUTTON_ORDER_TOTAL_REFRESH = 'MOLLIE_BUTTON_ORDER_TOTAL_REFRESH';
Expand All @@ -313,14 +321,15 @@ class Config

public static function getStatuses()
{
$isKlarnaDefault = Configuration::get(Config::MOLLIE_KLARNA_INVOICE_ON) === Config::MOLLIE_STATUS_DEFAULT;
$isAuthorizablePaymentInvoiceOnStatusDefault =
Configuration::get(Config::MOLLIE_AUTHORIZABLE_PAYMENT_INVOICE_ON_STATUS) === Config::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_DEFAULT;

return [
self::MOLLIE_AWAITING_PAYMENT => Configuration::get(self::MOLLIE_STATUS_AWAITING),
PaymentStatus::STATUS_PAID => Configuration::get(self::MOLLIE_STATUS_PAID),
OrderStatus::STATUS_COMPLETED => Configuration::get(self::MOLLIE_STATUS_COMPLETED),
PaymentStatus::STATUS_AUTHORIZED => $isKlarnaDefault ?
Configuration::get(self::MOLLIE_STATUS_PAID) : Configuration::get(self::MOLLIE_STATUS_KLARNA_AUTHORIZED),
PaymentStatus::STATUS_AUTHORIZED => $isAuthorizablePaymentInvoiceOnStatusDefault ?
Configuration::get(self::MOLLIE_STATUS_PAID) : Configuration::get(self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED),
PaymentStatus::STATUS_CANCELED => Configuration::get(self::MOLLIE_STATUS_CANCELED),
PaymentStatus::STATUS_EXPIRED => Configuration::get(self::MOLLIE_STATUS_EXPIRED),
RefundStatus::STATUS_REFUNDED => Configuration::get(self::MOLLIE_STATUS_REFUNDED),
Expand All @@ -333,7 +342,7 @@ public static function getStatuses()
self::STATUS_PAID_ON_BACKORDER => Configuration::get('PS_OS_OUTOFSTOCK_PAID'),
self::STATUS_PENDING_ON_BACKORDER => Configuration::get('PS_OS_OUTOFSTOCK_UNPAID'),
self::STATUS_ON_BACKORDER => Configuration::get('PS_OS_OUTOFSTOCK'),
self::MOLLIE_STATUS_KLARNA_SHIPPED => Configuration::get(self::MOLLIE_STATUS_KLARNA_SHIPPED),
self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED => Configuration::get(self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED),
self::MOLLIE_CHARGEBACK => Configuration::get(self::MOLLIE_STATUS_CHARGEBACK),
];
}
Expand All @@ -355,8 +364,8 @@ public static function getMollieOrderStatuses()
self::MOLLIE_STATUS_PARTIAL_REFUND,
self::MOLLIE_STATUS_AWAITING,
self::MOLLIE_STATUS_ORDER_COMPLETED,
self::MOLLIE_STATUS_KLARNA_AUTHORIZED,
self::MOLLIE_STATUS_KLARNA_SHIPPED,
self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_AUTHORIZED,
self::MOLLIE_AUTHORIZABLE_PAYMENT_STATUS_SHIPPED,
self::MOLLIE_STATUS_CHARGEBACK,
];
}
Expand Down
58 changes: 58 additions & 0 deletions src/DTO/Object/Company.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Mollie\DTO\Object;

class Company implements \JsonSerializable
{
/** @var string */
private $vatNumber;
/** @var string */
private $registrationNumber;

/**
* @return string
*/
public function getVatNumber(): string
{
return $this->vatNumber;
}

/**
* @param string $vatNumber
*
* @maps vatNumber
*/
public function setVatNumber(string $vatNumber)
{
$this->vatNumber = $vatNumber;
}

/**
* @return string
*/
public function getRegistrationNumber(): string
{
return $this->registrationNumber;
}

/**
* @param string $registrationNumber
*
* @maps registrationNumber
*/
public function setRegistrationNumber(string $registrationNumber)
{
$this->registrationNumber = $registrationNumber;
}

public function jsonSerialize()
{
$json = [];
$json['vatNumber'] = $this->getVatNumber();
$json['registrationNumber'] = $this->getRegistrationNumber();

return array_filter($json, static function ($val) {
return $val !== null && $val !== '';
});
}
}
142 changes: 142 additions & 0 deletions src/DTO/Object/Payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

namespace Mollie\DTO\Object;

class Payment implements \JsonSerializable
{
/** @var ?string */
private $cardToken;
/** @var string */
private $webhookUrl;
/** @var ?string */
private $issuer;
/** @var ?string */
private $customerId;
/** @var ?string */
private $applePayPaymentToken;
/** @var ?Company */
private $company;

/**
* @return ?string
*/
public function getCardToken()
{
return $this->cardToken;
}

/**
* @param string $cardToken
*
* @maps cardToken
*/
public function setCardToken(string $cardToken)
{
$this->cardToken = $cardToken;
}

/**
* @return string
*/
public function getWebhookUrl(): string
{
return $this->webhookUrl;
}

/**
* @param string $webhookUrl
*
* @maps webhookUrl
*/
public function setWebhookUrl(string $webhookUrl)
{
$this->webhookUrl = $webhookUrl;
}

/**
* @return ?string
*/
public function getIssuer()
{
return $this->issuer;
}

/**
* @param string $issuer
*
* @maps issuer
*/
public function setIssuer(string $issuer)
{
$this->issuer = $issuer;
}

/**
* @return ?string
*/
public function getCustomerId()
{
return $this->customerId;
}

/**
* @param string $customerId
*
* @maps customerId
*/
public function setCustomerId(string $customerId)
{
$this->customerId = $customerId;
}

/**
* @return ?string
*/
public function getApplePayPaymentToken()
{
return $this->applePayPaymentToken;
}

/**
* @param string $applePayPaymentToken
*
* @maps applePayPaymentToken
*/
public function setApplePayPaymentToken(string $applePayPaymentToken)
{
$this->applePayPaymentToken = $applePayPaymentToken;
}

/**
* @return ?Company
*/
public function getCompany()
{
return $this->company;
}

/**
* @param \Mollie\DTO\Object\Company $company
*
* @maps company
*/
public function setCompany(Company $company)
{
$this->company = $company;
}

public function jsonSerialize()
{
$result = [];
$result['cardToken'] = $this->getCardToken();
$result['webhookUrl'] = $this->getWebhookUrl();
$result['issuer'] = $this->getIssuer();
$result['customerId'] = $this->getCustomerId();
$result['applePayPaymentToken'] = $this->getApplePayPaymentToken();
$result['company'] = $this->getCompany() ? $this->getCompany()->jsonSerialize() : null;

return array_filter($result, static function ($val) {
return $val !== null && $val !== '';
});
}
}
Loading