Skip to content

Commit

Permalink
Update to fix error with relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhall17 committed Feb 1, 2020
1 parent 1ada14e commit 9af3a82
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/PaymentMethod/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ class Card extends StripeExtendedModel
'checks' => CardChecks::class
];

public $insertAttributes = [
'number',
'exp_month',
'exp_year',
'cvc'
];

public $updateAttributes = [
'exp_month',
'exp_year',
];

}
17 changes: 17 additions & 0 deletions src/Support/StripeAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function get($wheres, $limit = 0, $pagination = '')
public function insert(array $attributes)
{
$this->modelCheck();
$attributes = $this->flattenAttributes($attributes);
$object = $this->model::create($attributes);
return array_merge($object->jsonSerialize(), ['StripeObject' => $object]);
}
Expand All @@ -95,6 +96,7 @@ public function insert(array $attributes)
public function update($id, array $attributes)
{
$this->modelCheck();
$attributes = $this->flattenAttributes($attributes);
$object = $this->model::update($id, $attributes);
return array_merge($object->jsonSerialize(), ['StripeObject' => $object]);
}
Expand Down Expand Up @@ -149,4 +151,19 @@ public function processOptions($where = [], $limit = 0, $pagination = [])
return $options;
}

public function flattenAttributes($attributes)
{
$return_attributes = [];
foreach($attributes as $key => $attribute){
if(is_array($attribute)){
$return_attributes[$key] = $this->flattenAttributes($attribute);
} else if(is_object($attribute)){
$return_attributes[$key] = $this->flattenAttributes($attribute->getAttributes());
} else {
$return_attributes[$key] = $attribute;
}
}
return $return_attributes;
}

}

0 comments on commit 9af3a82

Please sign in to comment.