function testDelete_deletesThePaymentMethod() { $customer = Braintree_Customer::createNoValidate(array()); $creditCard = Braintree_CreditCard::createNoValidate(array('customerId' => $customer->id, 'number' => '5105105105105100', 'expirationDate' => '05/12')); Braintree_CreditCard::find($creditCard->token); Braintree_CreditCard::delete($creditCard->token); $this->setExpectedException('Braintree_Exception_NotFound'); Braintree_CreditCard::find($creditCard->token); }
function deleteCard($token, $token_id) { $OSCOM_Db = Registry::get('Db'); Braintree_Configuration::environment(MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_SERVER == 'Live' ? 'production' : 'sandbox'); Braintree_Configuration::merchantId(MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ID); Braintree_Configuration::publicKey(MODULE_PAYMENT_BRAINTREE_CC_PUBLIC_KEY); Braintree_Configuration::privateKey(MODULE_PAYMENT_BRAINTREE_CC_PRIVATE_KEY); try { Braintree_CreditCard::delete($token); } catch (Exception $e) { } return $OSCOM_Db->delete('customers_braintree_tokens', ['id' => $token_id, 'customers_id' => $_SESSION['customer_id'], 'braintree_token' => $token]) === 1; }
function deleteCard($token, $token_id) { global $customer_id; Braintree_Configuration::environment(MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_SERVER == 'Live' ? 'production' : 'sandbox'); Braintree_Configuration::merchantId(MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ID); Braintree_Configuration::publicKey(MODULE_PAYMENT_BRAINTREE_CC_PUBLIC_KEY); Braintree_Configuration::privateKey(MODULE_PAYMENT_BRAINTREE_CC_PRIVATE_KEY); try { Braintree_CreditCard::delete($token); } catch (Exception $e) { } tep_db_query("delete from customers_braintree_tokens where id = '" . (int) $token_id . "' and customers_id = '" . (int) $customer_id . "' and braintree_token = '" . tep_db_prepare_input(tep_db_input($token)) . "'"); return tep_db_affected_rows() === 1; }
/** * Deletes a record via the API * * @param object $model * @param mixed $conditions * @return bool */ public function delete(Model $model, $conditions = null) { $ids = $this->_getIdsToBeDeleted($model, $conditions); if ($ids === false) { return false; } $entity = $this->_getModelEntity($model); if (!empty($ids)) { foreach ($ids as $id) { try { switch ($entity) { case 'Customer': Braintree_Customer::delete($id); break; case 'Transaction': $this->showError(__('Transactions cannot be deleted', true)); return false; break; case 'CreditCard': Braintree_CreditCard::delete($id); break; case 'Address': $exploded = explode('|', $id); if (count($exploded) != 2) { return false; } list($customer_id, $address_id) = $exploded; Braintree_Address::delete($customer_id, $address_id); break; default: return false; break; } } catch (Exception $e) { $this->showError(print_r($e, true)); return false; } } } return true; }
public function deleteCard($token) { try { return Braintree_CreditCard::delete($token); } catch (Braintree_Exception $e) { Mage::logException($e); return false; } }
public function updateCard($config, $data) { $common = new Common(); $updateData = array(); $oldCardExists = false; $session = new Container('frontend'); \Braintree_Configuration::environment($config['payment_gateway']['tree_env']); \Braintree_Configuration::merchantId($config['payment_gateway']['merchant_id']); \Braintree_Configuration::publicKey($config['payment_gateway']['public_key']); \Braintree_Configuration::privateKey($config['payment_gateway']['private_key']); $cardDetails = $common->getUserCardDetails($config['api_url']['value'], array('user_id' => $session->userid)); //print_r($cardDetails); exit; $card = isset($cardDetails[0]) ? $cardDetails[0] : ''; if (!is_array($data)) { parse_str($data, $data); } if (isset($card) && is_array($card)) { try { $result = \Braintree_CreditCard::find($card['creditCardDetails_token']); $oldCardExists = true; } catch (\Exception $ex) { $oldCardExists = false; //echo $ex->getMessage(); } try { $delete = \Braintree_CreditCard::delete($card['creditCardDetails_token']); } catch (\Exception $ex) { //echo $ex->getMessage(); } } if (!isset($data['creditCardDetails_token']) && !isset($data['customerDetails_id'])) { $result = \Braintree_CreditCard::create(array('customerId' => isset($card['customerDetails_id']) ? $card['customerDetails_id'] : '', 'number' => $data['card_no'], 'cvv' => $data['cvv'], 'expirationDate' => $data['month'] . '/' . $data['year'], 'cardholderName' => $data['name_on_card'], 'options' => array('makeDefault' => true))); if ($result->success) { $data['creditCardDetails_token'] = $result->creditCard->token; $data['customerDetails_id'] = $result->creditCard->customerId; } else { return array('status' => 0, 'msg' => $result->message, 'errors' => $result->errors->deepAll()); } } $updateData['user_id'] = $session->userid; $updateData['card_expiration_hash'] = isset($data['card_expiration_hash']) ? $data['card_expiration_hash'] : md5($data['month'] . '-' . $data['Year']); $updateData['creditCardDetails_token'] = $data['creditCardDetails_token']; $updateData['customerDetails_id'] = $data['customerDetails_id']; isset($card['use_for_renew']) ? $updateData['use_for_renew'] = $card['use_for_renew'] : ''; isset($data['use_for_renew']) ? $updateData['use_for_renew'] = $data['use_for_renew'] : ''; $res = isset($card['id']) ? $this->api->curl($config['api_url']['value'] . '/api/card_details/' . $card['id'] . '/', $updateData, 'PUT') : $this->api->curl($config['api_url']['value'] . '/api/card_details/', $updateData, 'POST'); if ($res->getStatusCode() == 200 || $res->getStatusCode() == 201) { return array('status' => 1, 'msg' => 'Card details successfully updated..!!'); } else { return array('status' => 1, 'msg' => 'Failed to update card details..!!', 'errors' => json_decode($res->getBody(), true)); } }
/** * Delete the saved card in braintree given the credit card token * * @since 2.0 * @param string $token the braintree credit card token */ public function delete_saved_card($token) { try { Braintree_CreditCard::delete($token); } catch (Exception $e) { $this->add_debug_message($e->getMessage()); } }
/** * @param string $token * @return \Braintree_Result_Successful */ public function delete($token) { return \Braintree_CreditCard::delete($token); }