From 7170728177ddc7c445a94ec0f009932a91911a0f Mon Sep 17 00:00:00 2001 From: Nikolai R Kristiansen Date: Sat, 8 Aug 2015 12:49:54 +0200 Subject: [PATCH] Fix issue with card update when no previous card --- api/api_functions.php | 10 +++++----- api/card.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/api_functions.php b/api/api_functions.php index abb5ace..3c0afee 100644 --- a/api/api_functions.php +++ b/api/api_functions.php @@ -70,6 +70,9 @@ if( !function_exists('valid_phonenumber') ) { } function _get_cards($value) { + if($value === "") { + return array(); + } $u_cs = array(); $u_cards = explode(",", $value); foreach ($u_cards as $c) { @@ -134,9 +137,6 @@ function get_user_data($ids) { $result[$key] = $u_gs; } elseif($key == "cards") { - if($value === "") { - continue; // no cards - } $result[$key] = _get_cards($value); } } @@ -252,8 +252,8 @@ function get_card_owner_phone_number($card_number) { return $res[0][0]; } -function get_active_card_number($user) { - foreach($user['cards'] as $card) { +function get_active_card_number($cards) { + foreach($cards as $card) { if($card['is_active'] == "1") { return $card['card_number']; } diff --git a/api/card.php b/api/card.php index 3372eb7..9e8218d 100644 --- a/api/card.php +++ b/api/card.php @@ -76,7 +76,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST') { return_json_response(array('error' => "User with user_id '".$data['user_id']."' does not exist."), 400); } $user = $user_data[0]; - $active_card_number = get_active_card_number($user); + $active_card_number = get_active_card_number($user['cards']); /* If card number is attached to specified user, bail */ if($active_card_number && $active_card_number === $data['card_number']) {