dev-think-one /
laravel-gocardless-payment
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace GoCardlessPayment\Actions\Imports; |
||||
| 4 | |||||
| 5 | use GoCardlessPayment\GoCardlessPayment; |
||||
| 6 | use GoCardlessPayment\Makeable; |
||||
| 7 | use GoCardlessPayment\Models\GoCardlessMandate; |
||||
| 8 | use GoCardlessPro\Resources\Mandate; |
||||
| 9 | |||||
| 10 | class ImportMandateAction |
||||
| 11 | { |
||||
| 12 | use Makeable; |
||||
| 13 | |||||
| 14 | public readonly string $mandateId; |
||||
| 15 | |||||
| 16 | 6 | public function __construct(string $mandateId) |
|||
| 17 | { |
||||
| 18 | 6 | $this->mandateId = $mandateId; |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 19 | } |
||||
| 20 | |||||
| 21 | 6 | public function execute(): GoCardlessMandate |
|||
| 22 | { |
||||
| 23 | /** @var Mandate $mandate */ |
||||
| 24 | 6 | $mandate = GoCardlessPayment::api()->mandates()->get($this->mandateId); |
|||
|
0 ignored issues
–
show
The method
mandates() does not exist on GoCardlessPayment\Api. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 25 | |||||
| 26 | 6 | $customerId = data_get($mandate->links, 'customer'); |
|||
| 27 | |||||
| 28 | 6 | $localCustomer = GoCardlessPayment::localCustomerRepository()->findLocalCustomer($customerId); |
|||
| 29 | 6 | if (! $localCustomer) { |
|||
| 30 | 2 | throw new \Exception("Customer [{$customerId}] not found in local storage."); |
|||
| 31 | } |
||||
| 32 | |||||
| 33 | 4 | $reflect = new \ReflectionClass($mandate); |
|||
| 34 | 4 | $props = $reflect->getProperties(\ReflectionProperty::IS_PROTECTED); |
|||
| 35 | |||||
| 36 | 4 | $data = []; |
|||
| 37 | 4 | foreach ($props as $prop) { |
|||
| 38 | 4 | $data[$prop->getName()] = $prop->getValue($mandate); |
|||
| 39 | } |
||||
| 40 | |||||
| 41 | 4 | return GoCardlessPayment::modelClass('mandate')::updateOrCreate( |
|||
| 42 | 4 | [ |
|||
| 43 | 4 | 'id' => $mandate->id, |
|||
| 44 | 4 | ], |
|||
| 45 | 4 | [ |
|||
| 46 | 4 | 'customer_id' => $customerId, |
|||
| 47 | 4 | 'creditor_id' => data_get($mandate->links, 'creditor'), |
|||
| 48 | 4 | 'customer_bank_account_id' => data_get($mandate->links, 'customer_bank_account'), |
|||
| 49 | 4 | 'status' => $mandate->status, |
|||
| 50 | 4 | 'reference' => $mandate->reference, |
|||
| 51 | 4 | 'data' => $data, |
|||
| 52 | 4 | ] |
|||
| 53 | 4 | ); |
|||
| 54 | } |
||||
| 55 | } |
||||
| 56 |