|
|
@@ -18,6 +18,7 @@ use App\Data\Pagarme\Response\OrderResponseData\OrderResponseData;
|
|
|
use App\Enums\PaymentSplitStatusEnum;
|
|
|
use App\Enums\PaymentStatusEnum;
|
|
|
use App\Models\Address;
|
|
|
+use App\Models\Client;
|
|
|
use App\Models\Payment;
|
|
|
use App\Models\PaymentSplit;
|
|
|
use App\Models\Schedule;
|
|
|
@@ -163,6 +164,8 @@ class PagarmePaymentService
|
|
|
|
|
|
$order->requireId();
|
|
|
|
|
|
+ $this->saveExternalCustomerId($payment, $order);
|
|
|
+
|
|
|
return $order->toArray();
|
|
|
}
|
|
|
|
|
|
@@ -360,4 +363,40 @@ class PagarmePaymentService
|
|
|
{
|
|
|
return "payment-{$payment->id}-schedule-{$payment->schedule_id}";
|
|
|
}
|
|
|
+
|
|
|
+ // salva o external_customer_id do Pagar.me no Client apos criacao de ordem
|
|
|
+
|
|
|
+ private function saveExternalCustomerId(Payment $payment, OrderResponseData $order): void
|
|
|
+ {
|
|
|
+ $customerId = $order->customer?->id;
|
|
|
+ $customerCode = $order->customer?->code;
|
|
|
+
|
|
|
+ if (! $customerId && ! $customerCode) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $client = Client::find($payment->client_id);
|
|
|
+
|
|
|
+ if (! $client) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $updated = false;
|
|
|
+
|
|
|
+ if (! $client->external_customer_id && $customerId) {
|
|
|
+ $client->external_customer_id = $customerId;
|
|
|
+
|
|
|
+ $updated = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (! $client->external_customer_code && $customerCode) {
|
|
|
+ $client->external_customer_code = $customerCode;
|
|
|
+
|
|
|
+ $updated = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($updated) {
|
|
|
+ $client->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|