|
@@ -270,17 +270,50 @@ class ProviderService
|
|
|
|
|
|
|
|
public function updateBankAccount(int $id, array $bankAccountData): ?Provider
|
|
public function updateBankAccount(int $id, array $bankAccountData): ?Provider
|
|
|
{
|
|
{
|
|
|
- $provider = $this->findById($id);
|
|
|
|
|
|
|
+ $provider = Provider::with(['user', 'addresses.city', 'addresses.state'])->find($id);
|
|
|
|
|
|
|
|
if (! $provider) {
|
|
if (! $provider) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $this->pagarmeRecipientService->updateDefaultBankAccount($provider, $bankAccountData);
|
|
|
|
|
|
|
+ $bankAccountData['holder_name'] = $bankAccountData['holder_name'] ?? $provider->user?->name;
|
|
|
|
|
+ $bankAccountData['holder_document'] = $bankAccountData['holder_document'] ?? $provider->document;
|
|
|
|
|
+ $bankAccountData['holder_type'] = $bankAccountData['holder_type'] ?? 'individual';
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($provider->recipient_id)) {
|
|
|
|
|
+ $this->pagarmeRecipientService->createRecipientForProvider(
|
|
|
|
|
+ $provider,
|
|
|
|
|
+ $this->buildRecipientDataFromProvider($provider, $bankAccountData),
|
|
|
|
|
+ );
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->pagarmeRecipientService->updateDefaultBankAccount($provider, $bankAccountData);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return $provider->fresh(['user', 'profileMedia']);
|
|
return $provider->fresh(['user', 'profileMedia']);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private function buildRecipientDataFromProvider(Provider $provider, array $bankAccountData): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $address = $provider->addresses->first();
|
|
|
|
|
+
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'recipient_name' => $provider->user?->name,
|
|
|
|
|
+ 'recipient_email' => $provider->user?->email,
|
|
|
|
|
+ 'recipient_document' => $provider->document,
|
|
|
|
|
+ 'recipient_type' => 'individual',
|
|
|
|
|
+ 'recipient_payment_mode' => 'bank_transfer',
|
|
|
|
|
+ 'recipient_metadata' => [],
|
|
|
|
|
+ 'recipient_default_bank_account' => $bankAccountData,
|
|
|
|
|
+ 'birth_date' => $provider->birth_date,
|
|
|
|
|
+ 'phone' => $provider->user?->phone,
|
|
|
|
|
+ 'address' => $address?->address,
|
|
|
|
|
+ 'number' => $address?->number,
|
|
|
|
|
+ 'city' => $address?->city?->name,
|
|
|
|
|
+ 'state' => $address?->state?->code,
|
|
|
|
|
+ 'zip_code' => $address?->zip_code,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//
|
|
//
|
|
|
|
|
|
|
|
private function createProviderAddress(int $providerId, array $data): void
|
|
private function createProviderAddress(int $providerId, array $data): void
|