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 additional data send #18

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
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 !== '';
});
}
}
19 changes: 12 additions & 7 deletions src/DTO/OrderData.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Country;
use JsonSerializable;
use Mollie\DTO\Object\Amount;
use Mollie\DTO\Object\Payment;

class OrderData implements JsonSerializable
{
Expand Down Expand Up @@ -85,7 +86,7 @@ class OrderData implements JsonSerializable
private $lines;

/**
* @var array
* @var Payment
*/
private $payment;

Expand Down Expand Up @@ -358,17 +359,19 @@ public function setLines($lines)
}

/**
* @return array
* @return Payment
*/
public function getPayment()
public function getPayment(): Payment
{
return $this->payment;
}

/**
* @param array $payment
* @param \Mollie\DTO\Object\Payment $payment
*
* @maps payment
*/
public function setPayment($payment)
public function setPayment(Payment $payment)
{
$this->payment = $payment;
}
Expand Down Expand Up @@ -448,7 +451,7 @@ public function jsonSerialize()
'locale' => $this->getLocale(),
'orderNumber' => $this->getOrderNumber(),
'lines' => $lines,
'payment' => $this->getPayment(),
'payment' => $this->getPayment()->jsonSerialize(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't really be needed, it should work by default

'consumerDateOfBirth' => $this->getConsumerDateOfBirth(),
];

Expand All @@ -460,7 +463,9 @@ public function jsonSerialize()
$result['shippingAddress']['phone'] = $this->deliveryPhoneNumber;
}

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

private function cleanUpInput($input, $defaultValue = 'N/A')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ private function isIdentificationNumberValid(): bool

private function isVatNumberValid(): bool
{
$billingAddressId = $this->context->getAddressInvoiceId();
$billingAddressId = $this->context->getInvoiceAddressId();

/** @var \Address $billingAddress */
$billingAddress = $this->addressRepository->findOneBy([
'id_address' => (int) $billingAddressId,
'id_address' => $billingAddressId,
]);

/** @var \AddressFormat $addressFormat */
Expand Down
47 changes: 35 additions & 12 deletions src/Service/PaymentMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use Mollie\Api\Types\PaymentMethod;
use Mollie\Config\Config;
use Mollie\DTO\Object\Amount;
use Mollie\DTO\Object\Company;
use Mollie\DTO\Object\Payment;
use Mollie\DTO\OrderData;
use Mollie\DTO\PaymentData;
use Mollie\Exception\OrderCreationException;
Expand Down Expand Up @@ -352,14 +354,27 @@ public function getPaymentData(
if (isset($cart->id_address_invoice)) {
$billingAddress = new Address((int) $cart->id_address_invoice);

$company = new Company();

if (!empty($billingAddress->vat_number)) {
$company->setVatNumber($billingAddress->vat_number);
}

if (!empty($customer->siret)) {
$company->setRegistrationNumber($customer->siret);
}

$orderData->setBillingAddress($billingAddress);
$orderData->setBillingPhoneNumber($this->phoneNumberProvider->getFromAddress($billingAddress));
}

if (isset($cart->id_address_delivery)) {
$shippingAddress = new Address((int) $cart->id_address_delivery);

$orderData->setShippingAddress($shippingAddress);
$orderData->setDeliveryPhoneNumber($this->phoneNumberProvider->getFromAddress($shippingAddress));
}

$orderData->setOrderNumber($orderReference);
$orderData->setLocale($this->getLocale($molPaymentMethod->method));
$orderData->setEmail($customer->email);
Expand Down Expand Up @@ -391,30 +406,38 @@ public function getPaymentData(
(bool) Configuration::get('PS_GIFT_WRAPPING'),
$selectedVoucherCategory
));
$payment = [];
if ($cardToken) {
$payment['cardToken'] = $cardToken;

$payment = new Payment();

if (!empty($cardToken)) {
$payment->setCardToken($cardToken);
}
$payment['webhookUrl'] = $this->context->getModuleLink(

$payment->setWebhookUrl($this->context->getModuleLink(
'mollie',
'webhook',
[],
true
);
));

if ($issuer) {
$payment['issuer'] = $issuer;
if (!empty($issuer)) {
$payment->setIssuer($issuer);
}

if ($molPaymentMethod->id_method === PaymentMethod::CREDITCARD) {
$molCustomer = $this->handleCustomerInfo($cart->id_customer, $saveCard, $useSavedCard);
if ($molCustomer) {
$payment['customerId'] = $molCustomer->customer_id;

if ($molCustomer && !empty($molCustomer->customer_id)) {
$payment->setCustomerId($molCustomer->customer_id);
}
}

if ($molPaymentMethod->id_method === PaymentMethod::APPLEPAY && $applePayToken) {
$payment['applePayPaymentToken'] = $applePayToken;
if ($molPaymentMethod->id_method === PaymentMethod::APPLEPAY && !empty($applePayToken)) {
$payment->setApplePayPaymentToken($applePayToken);
}

if (isset($company)) {
$payment->setCompany($company);
}

$orderData->setPayment($payment);
Expand Down Expand Up @@ -466,7 +489,7 @@ private function removeNotSupportedMethods($methods, $mollieMethods)

private function getSupportedMollieMethods()
{
$address = new Address($this->context->getAddressInvoiceId());
$address = new Address($this->context->getInvoiceAddressId());
$country = new Country($address->id_country);

$cartAmount = $this->orderTotalProvider->getOrderTotal();
Expand Down
1 change: 0 additions & 1 deletion src/ServiceProvider/BaseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Mollie\ServiceProvider;

use League\Container\Container;
use Mollie;
use Mollie\Builder\ApiTestFeedbackBuilder;
use Mollie\Config\Config;
use Mollie\Factory\ModuleFactory;
Expand Down