Newer
Older
<?php
namespace QUI\ERP\Payments\Stripe\PaymentMethods;
use Exception;
use QUI;
use QUI\ERP\Accounting\Invoice\Invoice;
use QUI\ERP\Accounting\Invoice\InvoiceTemporary;
use QUI\ERP\Accounting\Invoice\InvoiceView;
use QUI\ERP\Order\AbstractOrder;
use QUI\ERP\Order\OrderInterface;
use QUI\ERP\Payments\Stripe\AbstractBasePayment;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use QUI\ERP\Payments\Stripe\Utils;
use Stripe\Exception\ApiErrorException;
use Stripe\PaymentIntent as StripePaymentIntent;
use Stripe\PaymentMethod;
/**
* Stripe payment with SEPA Direct Debit
*/
class SepaDebit extends AbstractBasePayment
{
/**
* @return string
*/
public function getTitle(): string
{
return $this->getLocale()->get('quiqqer/payment-stripe', 'payment.SepaDebit.title');
}
/**
* @return string
*/
public function getDescription(): string
{
return $this->getLocale()->get('quiqqer/payment-stripe', 'payment.SepaDebit.description');
}
/**
* Get title for frontend
*
* @return string
*/
public function getFrontendTitle(): string
{
return $this->getLocale()->get('quiqqer/payment-stripe', 'payment.frontend.SepaDebit.title');
}
/**
* Get description for frontend
*
* @return string
*/
public function getFrontendDescription(): string
{
return $this->getLocale()->get('quiqqer/payment-stripe', 'payment.frontend.SepaDebit.description');
}
/**
* Get title for the Payment step (OrderProcess)
*
* @return string
*/
public function getPaymentStepTitle(): string
{
return $this->getLocale()->get('quiqqer/payment-stripe', 'payment.PaymentStep.title.SepaDebit');
}
/**
* Get description step for the Payment step (OrderProcess)
*
* @return string
*/
public function getPaymentStepInfo(): string
{
return $this->getLocale()->get('quiqqer/payment-stripe', 'payment.PaymentStep.info.SepaDebit');
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
}
// /**
// * Return the payment icon (the URL path)
// * Can be overwritten
// *
// * @return string
// */
// public function getIcon(): string
// {
// return Payments::getInstance()->getHost() .
// URL_OPT_DIR .
// 'quiqqer/payment-stripe/bin/images/Payment_Card.png'; // TODO: richtiges Logo verwenden
// }
/**
* Get type string of Stripe PaymentMethod
*
* @return string
*/
public function getPaymentMethodType(): string
{
return PaymentMethod::TYPE_SEPA_DEBIT;
}
/**
* Return attributes for creating a PaymentIntent
*
* @param AbstractOrder $Order
* @param string $paymentMethodId - Stripe PaymentMethod ID
* @return StripePaymentIntent
*
* @throws ApiErrorException
* @throws QUI\Exception
*/
protected function createPaymentIntentForOrder(AbstractOrder $Order, string $paymentMethodId): StripePaymentIntent
{
return StripePaymentIntent::create([
'payment_method' => $paymentMethodId,
'amount' => Utils::getCentAmount($Order),
'currency' => mb_strtolower($Order->getCurrency()->getCode()),
'confirm' => true,
'description' => Utils::getPaymentDescriptionForOrder($Order),
'statement_descriptor' => Provider::getStatementDescriptor($Order),
'payment_method_types' => [
PaymentMethod::TYPE_SEPA_DEBIT
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
],
'metadata' => [
'orderUuid' => $Order->getUUID()
],
'mandate_data' => [
'customer_acceptance' => [
'type' => 'online',
'online' => [
'ip_address' => $_SERVER['REMOTE_ADDR'],
'user_agent' => $_SERVER['HTTP_USER_AGENT'],
],
],
]
]);
}
/**
* Return the extra text for the invoice
*
* @param Invoice|InvoiceTemporary|InvoiceView $Invoice |InvoiceView $Invoice
* @return string
*/
public function getInvoiceInformationText(Invoice | InvoiceTemporary | InvoiceView $Invoice): string
{
try {
return $Invoice->getCustomer()->getLocale()->get(
'quiqqer/payment-stripe',
'additional_invoice_text.Card'
);
} catch (Exception $Exception) {
QUI\System\Log::writeException($Exception);
return '';
}
}
public function canBeUsedInOrder(OrderInterface $order): bool
{
// Currency must be EUR
if ($order->getCurrency()->getCode() !== 'EUR') {
return false;
}
if ($order->getInvoiceAddress()->getCountry()->isEU()) {
return true;
}
// Some Non-EU countries are also part of SEPA
return match ($order->getInvoiceAddress()->getCountry()->getCode()) {
'CH', 'GB', 'SM', 'VA', 'AD', 'MC', 'IS', 'NO', 'LI' => true,
default => false,
};
}
}