From 9af3a82f0dea2151f9a970348ff39060ad9dc4aa Mon Sep 17 00:00:00 2001 From: Colin Hall Date: Sat, 1 Feb 2020 16:35:25 +0000 Subject: [PATCH] Update to fix error with relationships --- src/PaymentMethod/Card.php | 12 ++++++++++++ src/Support/StripeAPI.php | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/PaymentMethod/Card.php b/src/PaymentMethod/Card.php index e325850..8d69b5d 100644 --- a/src/PaymentMethod/Card.php +++ b/src/PaymentMethod/Card.php @@ -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', + ]; + } diff --git a/src/Support/StripeAPI.php b/src/Support/StripeAPI.php index 1b385ce..4d6251d 100644 --- a/src/Support/StripeAPI.php +++ b/src/Support/StripeAPI.php @@ -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]); } @@ -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]); } @@ -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; + } + } \ No newline at end of file