Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
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
67
68
69
70
71
72
73
74
75
76
77
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
122
123
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
<?php
namespace QUI\ERP\Payments\Stripe\PaymentMethods\Recurring;
use Exception;
use QUI;
use QUI\ERP\Accounting\Invoice\Invoice;
use QUI\ERP\Accounting\Invoice\InvoiceView;
use QUI\ERP\Accounting\Payments\Payments;
use QUI\ERP\Order\AbstractOrder;
use QUI\ERP\Order\OrderInterface;
use QUI\ERP\Payments\Stripe\Provider;
use QUI\ERP\Payments\Stripe\Utils;
use Stripe\Exception\ApiErrorException;
use Stripe\PaymentIntent;
use Stripe\PaymentIntent as StripePaymentIntent;
use Stripe\PaymentMethod;
use Stripe\Subscription;
use Stripe\Subscription as StripeSubscription;
/**
* Stripe payment with SEPA Direct Debit for recurring payments
*/
class SepaDebit extends AbstractBaseRecurringPayment
{
/**
* @return string
*/
public function getTitle(): string
{
return $this->getLocale()->get('quiqqer/payment-stripe', 'payment.Recurring.SepaDebit.title');
}
/**
* @return string
*/
public function getDescription(): string
{
return $this->getLocale()->get('quiqqer/payment-stripe', 'payment.Recurring.SepaDebit.description');
}
/**
* Get title for frontend
*
* @return string
*/
public function getFrontendTitle(): string
{
return $this->getLocale()->get('quiqqer/payment-stripe', 'payment.frontend.Recurring.SepaDebit.title');
}
/**
* Get description for frontend
*
* @return string
*/
public function getFrontendDescription(): string
{
return $this->getLocale()->get('quiqqer/payment-stripe', 'payment.frontend.Recurring.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.Recurring.PaymentStep.info.SepaDebit');
}
// /**
// * 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
// }
/**
* Get type string of Stripe PaymentMethod
*
* @return string
*/
public function getPaymentMethodType(): string
{
return PaymentMethod::TYPE_SEPA_DEBIT;
}
/**
* Return the extra text for the invoice
*
* @param Invoice|InvoiceView $Invoice
* @return string
*/
public function getInvoiceInformationText($Invoice): string
{
try {
return $Invoice->getCustomer()->getLocale()->get(
'quiqqer/payment-stripe',
'additional_invoice_text.SepaDebit'
);
} catch (Exception $Exception) {
QUI\System\Log::writeException($Exception);
return '';
}
}
/**
* 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()),
'confirmation_method' => 'manual',
'confirm' => true,
'setup_future_usage' => 'off_session',
'use_stripe_sdk' => true,
'description' => Utils::getPaymentDescriptionForOrder($Order),
'statement_descriptor' => Provider::getStatementDescriptor($Order),
'metadata' => [
'orderUuid' => $Order->getUUID()
],
'payment_method_types' => [
PaymentMethod::TYPE_SEPA_DEBIT
],
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
'mandate_data' => [
'customer_acceptance' => [
'type' => 'online',
'online' => [
'ip_address' => $_SERVER['REMOTE_ADDR'],
'user_agent' => $_SERVER['HTTP_USER_AGENT'],
],
],
]
]);
}
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,
};
}
/**
* Confirms a PaymentIntent with status "requires_confirmation" for a subscription.
*
* @param StripeSubscription $subscription
* @param StripePaymentIntent $paymentIntent
* @return void
* @throws ApiErrorException
*/
public function confirmPaymentIntentForSubscription(
Subscription $subscription,
PaymentIntent $paymentIntent
): void {
Provider::setupApi();
$data = [
'mandate_data' => [
'customer_acceptance' => [
'type' => 'online',
'online' => [
'ip_address' => $_SERVER['REMOTE_ADDR'],
'user_agent' => $_SERVER['HTTP_USER_AGENT'],
],
],
]
];
$paymentIntent->confirm($data);
}
}