PagarmePaymentService.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. <?php
  2. namespace App\Services\Pagarme;
  3. use App\Data\Pagarme\Customer\CustomerRequestData;
  4. use App\Data\Pagarme\Customer\Parts\Request\AddressData;
  5. use App\Data\Pagarme\Customer\Parts\Request\PhoneData;
  6. use App\Data\Pagarme\Customer\Parts\Request\PhonesData;
  7. use App\Data\Pagarme\Order\OrderRequestData;
  8. use App\Data\Pagarme\Order\OrderResponseData;
  9. use App\Data\Pagarme\Order\Parts\Request\CreditCardData;
  10. use App\Data\Pagarme\Order\Parts\Request\ItemData;
  11. use App\Data\Pagarme\Order\Parts\Request\PaymentData;
  12. use App\Data\Pagarme\Order\Parts\Request\PixAdditionalInformationData;
  13. use App\Data\Pagarme\Order\Parts\Request\PixData;
  14. use App\Data\Pagarme\Order\Parts\Request\SplitData;
  15. use App\Data\Pagarme\Order\Parts\Request\SplitOptionsData;
  16. use App\Enums\PaymentSplitStatusEnum;
  17. use App\Enums\PaymentStatusEnum;
  18. use App\Models\Address;
  19. use App\Models\Cart;
  20. use App\Models\Client;
  21. use App\Models\Payment;
  22. use App\Models\PaymentSplit;
  23. use App\Models\Schedule;
  24. use App\Services\Pagarme\Concerns\FormatsPagarmeData;
  25. use App\Services\Pagarme\Concerns\MocksPagarmeRequests;
  26. use App\Services\Pagarme\Concerns\SendsPagarmeRequests;
  27. use Illuminate\Support\Facades\Log;
  28. use Illuminate\Support\Str;
  29. class PagarmePaymentService
  30. {
  31. use FormatsPagarmeData;
  32. use MocksPagarmeRequests;
  33. use SendsPagarmeRequests;
  34. public function calculatePaymentAmounts(float $serviceAmount, string $paymentMethod, ?Schedule $schedule = null): array
  35. {
  36. if ($serviceAmount <= 0) {
  37. throw new \InvalidArgumentException('Valor do servico precisa ser maior que zero.');
  38. }
  39. if (! in_array($paymentMethod, ['credit_card', 'pix'], true)) {
  40. throw new \InvalidArgumentException('Forma de pagamento invalida.');
  41. }
  42. $platformFeeRate = $this->platformFeeRate($paymentMethod, $schedule);
  43. $platformFee = round($serviceAmount * $platformFeeRate, 2);
  44. $grossAmount = round($serviceAmount + $platformFee, 2);
  45. if ($platformFee > 0 && empty(config('services.pagarme.platform_recipient_id'))) {
  46. throw new \InvalidArgumentException('PAGARME_PLATFORM_RECIPIENT_ID precisa estar configurado para receber a taxa da plataforma no split.');
  47. }
  48. return [
  49. 'service_amount' => round($serviceAmount, 2),
  50. 'platform_fee_amount' => $platformFee,
  51. 'gross_amount' => $grossAmount,
  52. ];
  53. }
  54. public function platformFeeRates(): array
  55. {
  56. return [
  57. 'pix' => (float) config('services.pagarme.platform_pix_fee_rate'),
  58. 'credit_card' => (float) config('services.pagarme.platform_credit_card_fee_rate'),
  59. 'cart_min_3_schedules' => (float) config('services.pagarme.platform_cart_min_3_schedules_fee_rate'),
  60. ];
  61. }
  62. private function platformFeeRate(string $paymentMethod, ?Schedule $schedule = null): float
  63. {
  64. if ($schedule && $this->scheduleBelongsToCartWithAtLeastThreeItems($schedule)) {
  65. return (float) config('services.pagarme.platform_cart_min_3_schedules_fee_rate');
  66. }
  67. return $paymentMethod === 'credit_card'
  68. ? (float) config('services.pagarme.platform_credit_card_fee_rate')
  69. : (float) config('services.pagarme.platform_pix_fee_rate');
  70. }
  71. private function scheduleBelongsToCartWithAtLeastThreeItems(Schedule $schedule): bool
  72. {
  73. return Cart::query()
  74. ->whereHas('items', fn ($query) => $query->where('schedule_id', $schedule->id))
  75. ->whereHas('items', null, '>=', 3)
  76. ->exists();
  77. }
  78. public function processPayment(
  79. Payment $payment,
  80. Schedule $schedule,
  81. string $paymentMethod,
  82. ?string $cardId = null,
  83. array $options = [],
  84. ): array {
  85. $grossAmount = (float) $payment->gross_amount;
  86. $items = $this->buildOrderItems($schedule, $grossAmount);
  87. $customer = $this->buildCustomer($schedule, $options);
  88. $split = $this->buildSplit($payment, $options);
  89. $pixOptions = config('services.pagarme.pix_disable_split')
  90. ? []
  91. : ['split' => $split];
  92. $orderOptions = array_merge(['split' => $split], $pixOptions);
  93. if ($paymentMethod === 'credit_card') {
  94. $creditCard = new CreditCardData(
  95. cardId: $cardId,
  96. installments: $payment->installments,
  97. statementDescriptor: Str::limit((string) config('app.name', 'SOFTPAR'), 13, ''),
  98. operationType: 'auth_and_capture',
  99. );
  100. $result = $this->createOrderWithCreditCard(
  101. payment: $payment,
  102. items: $items,
  103. customer: $customer,
  104. creditCard: $creditCard,
  105. options: $orderOptions,
  106. );
  107. $this->logCreditCardOrderResult($payment, $result, 'create_order');
  108. $orderStatus = OrderResponseData::fromArray($result)->paymentStatus();
  109. if (! in_array($orderStatus, [PaymentStatusEnum::PAID, PaymentStatusEnum::AUTHORIZED], true)) {
  110. return $result;
  111. }
  112. return $result;
  113. }
  114. $pixData = new PixData(
  115. expiresIn: 1800,
  116. additionalInformation: [
  117. new PixAdditionalInformationData(
  118. name: 'Agendamento',
  119. value: (string) $schedule->id,
  120. ),
  121. ],
  122. );
  123. return $this->createOrderWithPix(
  124. payment: $payment,
  125. items: $items,
  126. customer: $customer,
  127. pix: $pixData,
  128. options: $pixOptions,
  129. );
  130. }
  131. public function createOrderWithCreditCard(
  132. Payment $payment,
  133. array $items,
  134. CustomerRequestData $customer,
  135. CreditCardData $creditCard,
  136. array $options = []
  137. ): array {
  138. return $this->createOrder(
  139. payment: $payment,
  140. items: $items,
  141. customer: $customer,
  142. paymentMethod: OrderRequestData::creditCardPaymentMethod(
  143. creditCard: $creditCard,
  144. split: is_array($options['split'] ?? null) ? $options['split'] : null,
  145. ),
  146. options: $options,
  147. );
  148. }
  149. public function createOrderWithPix(
  150. Payment $payment,
  151. array $items,
  152. CustomerRequestData $customer,
  153. PixData $pix,
  154. array $options = []
  155. ): array {
  156. return $this->createOrder(
  157. payment: $payment,
  158. items: $items,
  159. customer: $customer,
  160. paymentMethod: OrderRequestData::pixPaymentMethod(
  161. pix: $pix,
  162. split: is_array($options['split'] ?? null) ? $options['split'] : null,
  163. ),
  164. options: $options,
  165. );
  166. }
  167. public function createOrder(
  168. Payment $payment,
  169. array $items,
  170. CustomerRequestData $customer,
  171. PaymentData $paymentMethod,
  172. array $options = []
  173. ): array {
  174. $metadata = array_merge([
  175. 'payment_id' => (string) $payment->id,
  176. 'schedule_id' => (string) $payment->schedule_id,
  177. 'client_id' => (string) $payment->client_id,
  178. 'provider_id' => (string) $payment->provider_id,
  179. ], $options['metadata'] ?? []);
  180. $requestData = new OrderRequestData(
  181. code: $payment->ensureGatewayCode(),
  182. items: $items,
  183. payments: [$paymentMethod],
  184. metadata: $metadata,
  185. customer: $customer,
  186. customerId: $options['customer_id'] ?? null,
  187. closed: $options['closed'] ?? true,
  188. channel: $options['channel'] ?? null,
  189. );
  190. if ($this->shouldMockPagarmeRequest()) {
  191. $order = OrderResponseData::fromArray(
  192. $this->mockOrderResponse($payment, $requestData, $paymentMethod),
  193. );
  194. $order->requireId();
  195. $this->saveExternalCustomerId($payment, $order);
  196. return $order->toArray();
  197. }
  198. $order = OrderResponseData::fromArray($this->pagarmeRequest(
  199. method: 'POST',
  200. path: '/orders',
  201. payload: $requestData,
  202. idempotencyKey: $this->idempotencyKey($payment),
  203. errorMessage: 'Erro ao criar pedido de pagamento no Pagar.me.',
  204. ));
  205. $order->requireId();
  206. $this->saveExternalCustomerId($payment, $order);
  207. return $order->toArray();
  208. }
  209. //
  210. public function applyGatewayResponseToPayment(Payment $payment, array $orderResponse): Payment
  211. {
  212. $order = OrderResponseData::fromArray($orderResponse);
  213. $newStatus = $order->paymentStatus();
  214. $failureCode = null;
  215. $failureMessage = null;
  216. if ($newStatus === PaymentStatusEnum::FAILED) {
  217. $failureCode = $order->failureCode();
  218. $failureMessage = $order->failureMessage();
  219. $this->logCreditCardOrderResult($payment, $orderResponse, 'webhook_failed');
  220. }
  221. $gatewayFeeCents = $order->lastTransaction()?->cost ?? 0;
  222. $gatewayFee = $gatewayFeeCents > 0 ? round($gatewayFeeCents / 100, 2) : 0;
  223. $gatewayPayload = $newStatus === PaymentStatusEnum::FAILED
  224. ? $this->normalizeFailedGatewayPayload($orderResponse, $failureCode, $failureMessage)
  225. : $orderResponse;
  226. $payment->forceFill([
  227. 'gateway_provider' => 'pagarme',
  228. 'gateway_entity_reference' => $order->gatewayEntityReference(),
  229. 'gateway_entity_label' => $order->gatewayEntityLabel(),
  230. 'gateway_operation_reference' => $order->gatewayOperationReference(),
  231. 'gateway_operation_label' => $order->gatewayOperationLabel(),
  232. 'status' => $newStatus,
  233. 'paid_at' => $order->paidAt(),
  234. 'authorized_at' => $order->authorizedAt(),
  235. 'gateway_payload' => $gatewayPayload,
  236. 'gateway_fee_amount' => $gatewayFee,
  237. 'failure_code' => $failureCode,
  238. 'failure_message' => $failureMessage,
  239. ])->save();
  240. $splitStatus = match ($newStatus) {
  241. PaymentStatusEnum::PAID => PaymentSplitStatusEnum::TRANSFERRED,
  242. PaymentStatusEnum::FAILED => PaymentSplitStatusEnum::FAILED,
  243. PaymentStatusEnum::CANCELLED => PaymentSplitStatusEnum::CANCELLED,
  244. PaymentStatusEnum::AUTHORIZED => PaymentSplitStatusEnum::PROCESSING,
  245. default => PaymentSplitStatusEnum::PENDING,
  246. };
  247. PaymentSplit::query()
  248. ->where('payment_id', $payment->id)
  249. ->update(['status' => $splitStatus]);
  250. return $payment->fresh();
  251. }
  252. //
  253. private function mockOrderResponse(
  254. Payment $payment, OrderRequestData $requestData, PaymentData $paymentMethod,
  255. ): array {
  256. $payload = $requestData->toArray();
  257. $now = now()->toISOString();
  258. $orderId = $this->mockPagarmeId('or', $payment->id);
  259. $chargeId = $this->mockPagarmeId('ch', $payment->id);
  260. $transactionId = $this->mockPagarmeId('tran', $payment->id);
  261. $amount = array_sum(array_map(
  262. static fn (array $item): int => ((int) ($item['amount'] ?? 0)) * ((int) ($item['quantity'] ?? 1)),
  263. $payload['items'] ?? [],
  264. ));
  265. $isCreditCard = $paymentMethod->paymentMethod === 'credit_card';
  266. $chargeStatus = $isCreditCard ? 'paid' : 'pending';
  267. $transactionStatus = $isCreditCard ? 'captured' : 'waiting_payment';
  268. $transaction = [
  269. 'id' => $transactionId,
  270. 'status' => $transactionStatus,
  271. 'amount' => $amount,
  272. 'cost' => 0,
  273. 'created_at' => $now,
  274. 'acquirer_message' => $isCreditCard ? 'Transacao mockada aprovada.' : null,
  275. 'gateway_response' => [
  276. 'code' => $isCreditCard ? '00' : 'mock_waiting_payment',
  277. 'message' => 'Pagar.me mock local.',
  278. ],
  279. ];
  280. if (! $isCreditCard) {
  281. $transaction['qr_code'] = '00020101021226880014br.gov.bcb.pix2566mock.local/pix/'.$payment->id;
  282. $transaction['qr_code_url'] = url("/mock/pix/{$payment->id}");
  283. $transaction['expires_at'] = now()->addMinutes(30)->toISOString();
  284. }
  285. return [
  286. 'id' => $orderId,
  287. 'code' => $requestData->code,
  288. 'amount' => $amount,
  289. 'currency' => 'BRL',
  290. 'closed' => true,
  291. 'status' => $chargeStatus,
  292. 'items' => $payload['items'] ?? [],
  293. 'customer' => $this->mockCustomerResponse($requestData),
  294. 'charges' => [[
  295. 'id' => $chargeId,
  296. 'status' => $chargeStatus,
  297. 'amount' => $amount,
  298. 'currency' => 'BRL',
  299. 'paid_at' => $isCreditCard ? $now : null,
  300. 'created_at' => $now,
  301. 'expires_at' => $isCreditCard ? null : now()->addMinutes(30)->toISOString(),
  302. 'last_transaction' => $transaction,
  303. ]],
  304. 'checkouts' => [],
  305. 'metadata' => array_merge($requestData->metadata, ['mocked' => true]),
  306. 'created_at' => $now,
  307. 'updated_at' => $now,
  308. 'closed_at' => $now,
  309. ];
  310. }
  311. private function mockCustomerResponse(OrderRequestData $requestData): array
  312. {
  313. $customer = $requestData->customer?->toArray() ?? [];
  314. return array_merge($customer, [
  315. 'id' => $requestData->customerId ?: $this->mockPagarmeId('cus', $customer['code'] ?? $requestData->code),
  316. 'delinquent' => false,
  317. ]);
  318. }
  319. //
  320. private function buildCustomer(Schedule $schedule, array $options = []): CustomerRequestData
  321. {
  322. $client = $schedule->client;
  323. $user = $client->user()->first(['id', 'name', 'email', 'phone']);
  324. $address = Address::with(['city.state', 'state'])->find($schedule->address_id);
  325. foreach ([
  326. 'nome' => $user?->name,
  327. 'email' => $user?->email,
  328. 'documento' => $client->document,
  329. ] as $field => $value) {
  330. if ($value === null || $value === '') {
  331. throw new \InvalidArgumentException("Cliente precisa ter {$field} para criar pedido no Pagar.me.");
  332. }
  333. }
  334. if (! $address) {
  335. throw new \InvalidArgumentException('Endereco do agendamento nao encontrado para criar pedido no Pagar.me.');
  336. }
  337. $document = $this->customerDocument($client->document);
  338. $documentType = $this->customerDocumentType($document);
  339. $phone = $this->buildPhonePayload($user->phone)
  340. ?: $this->buildPhonePayload($options['phone'] ?? null);
  341. $state = $address->state?->code ?? $address->city?->state?->code;
  342. $city = $address->city?->name;
  343. $zipCode = $this->digits($address->zip_code);
  344. $line1 = implode(', ', array_filter([
  345. $address->number ?: 'S/N',
  346. $address->address,
  347. $address->district,
  348. ]));
  349. foreach ([
  350. 'documento' => $document,
  351. 'estado' => $state,
  352. 'cidade' => $city,
  353. 'cep' => $zipCode,
  354. 'endereco' => $line1,
  355. 'telefone' => $phone,
  356. ] as $field => $value) {
  357. if ($value === null || $value === '' || $value === []) {
  358. throw new \InvalidArgumentException("Cliente precisa ter {$field} valido para criar pedido no Pagar.me.");
  359. }
  360. }
  361. $customerAddress = new AddressData(
  362. line1: $line1,
  363. line2: $address->complement ?: $address->instructions,
  364. zipCode: $zipCode,
  365. city: $city,
  366. state: $state,
  367. country: 'BR',
  368. );
  369. $customerPhones = null;
  370. if ($phone) {
  371. $customerPhones = new PhonesData(
  372. mobilePhone: new PhoneData(
  373. countryCode: $phone['country_code'],
  374. areaCode: $phone['area_code'],
  375. number: $phone['number'],
  376. ),
  377. );
  378. }
  379. return new CustomerRequestData(
  380. name: $user->name,
  381. email: $user->email,
  382. document: $document,
  383. type: $documentType === 'CNPJ' ? 'company' : 'individual',
  384. documentType: $documentType,
  385. code: $client->ensureGatewayCode(),
  386. address: $customerAddress,
  387. phones: $customerPhones,
  388. );
  389. }
  390. private function buildOrderItems(Schedule $schedule, float $grossAmount): array
  391. {
  392. $description = $schedule->customSchedule?->serviceType?->description
  393. ?? "Servico {$schedule->id}";
  394. return [new ItemData(
  395. code: "schedule-{$schedule->id}",
  396. amount: OrderRequestData::amountInCents($grossAmount),
  397. quantity: 1,
  398. description: $description,
  399. )];
  400. }
  401. private function buildPhonePayload(?string $phone): ?array
  402. {
  403. $digits = $this->digits($phone);
  404. if (strlen($digits) < 10) {
  405. return null;
  406. }
  407. if (str_starts_with($digits, '55')) {
  408. $digits = substr($digits, 2);
  409. }
  410. return [
  411. 'country_code' => '55',
  412. 'area_code' => substr($digits, 0, 2),
  413. 'number' => substr($digits, 2),
  414. ];
  415. }
  416. private function buildSplit(Payment $payment, array $options): array
  417. {
  418. $transfers = PaymentSplit::query()
  419. ->where('payment_id', $payment->id)
  420. ->get();
  421. $split = OrderRequestData::splitFromTransfers($transfers);
  422. $platformRecipientId = config('services.pagarme.platform_recipient_id');
  423. if (empty($platformRecipientId)) {
  424. return $split;
  425. }
  426. $orderAmountCents = OrderRequestData::amountInCents((float) $payment->gross_amount);
  427. $providerTotalCents = array_sum(array_map(
  428. static fn (SplitData $s) => $s->amount,
  429. $split,
  430. ));
  431. $platformAmountCents = $orderAmountCents - $providerTotalCents;
  432. if ($platformAmountCents > 0) {
  433. $split[] = new SplitData(
  434. amount: $platformAmountCents,
  435. recipientId: $platformRecipientId,
  436. type: 'flat',
  437. options: new SplitOptionsData(
  438. chargeProcessingFee: true,
  439. chargeRemainderFee: true,
  440. liable: true,
  441. ),
  442. );
  443. }
  444. return $split;
  445. }
  446. //
  447. private function isMisleadingGatewayCode(mixed $code): bool
  448. {
  449. if ($code === null || $code === '') {
  450. return false;
  451. }
  452. $code = mb_strtolower((string) $code);
  453. return preg_match('/^[1-2]\d{2}$/', $code) === 1
  454. || in_array($code, ['00', '0', 'approved', 'success'], true);
  455. }
  456. private function logCreditCardOrderResult(Payment $payment, array $orderResponse, string $source): void
  457. {
  458. $order = OrderResponseData::fromArray($orderResponse);
  459. $charge = $order->firstCharge();
  460. $transaction = $order->lastTransaction();
  461. $failureCode = $order->failureCode();
  462. Log::channel('pagarme')->info('Pagar.me credit card order result', [
  463. 'source' => $source,
  464. 'payment_id' => $payment->id,
  465. 'provider_id' => $payment->provider_id,
  466. 'order_id' => $order->id,
  467. 'order_status' => $order->status,
  468. 'charge_id' => $charge?->id,
  469. 'charge_status' => $charge?->status,
  470. 'transaction_id' => $transaction?->id,
  471. 'transaction_status' => $transaction?->status,
  472. 'failure_code' => $failureCode,
  473. 'failure_message' => $order->failureMessage(),
  474. 'acquirer_message' => $transaction?->acquirerMessage,
  475. 'gateway_response' => $this->normalizeGatewayResponseForFailure(
  476. $transaction?->gatewayResponse ?? [],
  477. $failureCode,
  478. ),
  479. ]);
  480. }
  481. private function normalizeFailedGatewayPayload(array $payload, ?string $failureCode, ?string $failureMessage): array
  482. {
  483. $payload['failure_code'] = $failureCode;
  484. $payload['failure_message'] = $failureMessage;
  485. if (isset($payload['charges'][0]['last_transaction']['gateway_response'])
  486. && is_array($payload['charges'][0]['last_transaction']['gateway_response'])) {
  487. $payload['charges'][0]['last_transaction']['gateway_response'] = $this->normalizeGatewayResponseForFailure(
  488. $payload['charges'][0]['last_transaction']['gateway_response'],
  489. $failureCode,
  490. );
  491. }
  492. return $payload;
  493. }
  494. private function normalizeGatewayResponseForFailure(array $gatewayResponse, ?string $failureCode): array
  495. {
  496. $code = $gatewayResponse['code'] ?? null;
  497. if (! $failureCode || ! $this->isMisleadingGatewayCode($code)) {
  498. return $gatewayResponse;
  499. }
  500. $gatewayResponse['raw_code'] = $code;
  501. $gatewayResponse['code'] = $failureCode;
  502. return $gatewayResponse;
  503. }
  504. private function roundMoneyUp(float $amount): float
  505. {
  506. return ceil($amount * 100) / 100;
  507. }
  508. // evita criacao duplicada de payment
  509. private function idempotencyKey(Payment $payment): string
  510. {
  511. if (! empty($payment->idempotency_key)) {
  512. return $payment->idempotency_key;
  513. }
  514. $key = 'order-'.(string) \Illuminate\Support\Str::uuid();
  515. $payment->forceFill(['idempotency_key' => $key])->save();
  516. return $key;
  517. }
  518. // salva o gateway_customer_id do Pagar.me no Client apos criacao de ordem
  519. private function saveExternalCustomerId(Payment $payment, OrderResponseData $order): void
  520. {
  521. $customerId = $order->customer?->id;
  522. $customerCode = $order->customer?->code;
  523. if (! $customerId && ! $customerCode) {
  524. return;
  525. }
  526. $client = Client::find($payment->client_id);
  527. if (! $client) {
  528. return;
  529. }
  530. $updated = false;
  531. if (! $client->gateway_customer_id && $customerId) {
  532. $client->gateway_customer_id = $customerId;
  533. $updated = true;
  534. }
  535. if (! $client->gateway_customer_code && $customerCode) {
  536. $client->gateway_customer_code = $customerCode;
  537. $updated = true;
  538. }
  539. if ($updated) {
  540. $client->save();
  541. }
  542. }
  543. }