/** * Action to allow users to delete payment methods * * @return Mage_Core_Controller_Varien_Action * * @throws Exception */ public function removeAction() { // Check we've recieved a payment ID $token = $this->getRequest()->getParam('id'); if (!$token) { $this->_getSession()->addError('Please select a saved payment entry to remove.'); return $this->_redirectReferer(); } // Grab a new instance of the wrapper $wrapper = Mage::getModel('gene_braintree/wrapper_braintree'); // Init the braintree wrapper $wrapper->init(); // Load the payment method from Braintree try { $paymentMethod = Braintree_PaymentMethod::find($token); } catch (Exception $e) { $this->_getSession()->addError('The requested payment method cannot be found.'); return $this->_redirectReferer(); } // Check that this is the users payment method, we have to use a custom method as Braintree don't return the PayPal customer ID if (!$wrapper->customerOwnsMethod($paymentMethod)) { $this->_getSession()->addError('You do not have permission to modify this payment method.'); return $this->_redirectReferer(); } // Remove the payment method Braintree_PaymentMethod::delete($token); // Inform the user of the great news $this->_getSession()->addSuccess('Saved payment has been successfully deleted.'); return $this->_redirectReferer(); }
/** * Delete a payment method within Braintree * * @param $token * * @return bool|\Braintree_Result_Successful */ public function deletePaymentMethod($token) { try { return Braintree_PaymentMethod::delete($token); } catch (Exception $e) { Gene_Braintree_Model_Debug::log($e); } return false; }
function testDelete_worksWithPayPalAccounts() { $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand()); $customer = Braintree_Customer::createNoValidate(); $nonce = Braintree_HttpClientApi::nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'PAYPAL_CONSENT_CODE', 'token' => $paymentMethodToken))); $paypalAccountResult = Braintree_PaymentMethod::create(array('customerId' => $customer->id, 'paymentMethodNonce' => $nonce)); $this->assertTrue($paypalAccountResult->success); Braintree_PaymentMethod::delete($paymentMethodToken); $this->setExpectedException('Braintree_Exception_NotFound'); Braintree_PaymentMethod::find($paymentMethodToken); }
} else { $updateResult = Braintree_PaymentMethod::update($_POST['token'], array('billingAddress' => array('streetAddress' => $_POST['streetAddress'], 'options' => array('updateExisting' => $_POST['updateExisting'])))); } print_r($updateResult); } else { if ($_POST['_act'] == 'findPaymentMethod') { $paymentMethod = Braintree_PaymentMethod::find($_POST['token']); print_r($paymentMethod); } else { if ($_POST['_act'] == 'deletePaymentMethod') { $search = (string) $_POST['token']; $file = './data/token.txt'; $contents = file_get_contents($file); echo $contents = str_replace($_POST['token'], trim((string) $_POST['token'] . "_DELETED\r\n"), $contents); file_put_contents($file, $contents); $paymentMethod = Braintree_PaymentMethod::delete($_POST['token']); print_r($paymentMethod); } else { if ($_POST['_act'] == 'createSubMerchant') { $result = Braintree_MerchantAccount::create(array('individual' => array('firstName' => $_POST['firstName'], 'lastName' => $_POST['lastName'], 'email' => $_POST['email'], 'phone' => $_POST['phone'], 'dateOfBirth' => $_POST['dateOfBirth'], 'ssn' => $_POST['ssn'], 'address' => array('streetAddress' => $_POST['streetAddress'], 'locality' => $_POST['locality'], 'region' => $_POST['region'], 'postalCode' => $_POST['postalCode'])), 'business' => array('legalName' => $_POST['legalName'], 'dbaName' => $_POST['dbaName'], 'taxId' => $_POST['taxId'], 'address' => array('streetAddress' => $_POST['streetAddress2'], 'locality' => $_POST['locality2'], 'region' => $_POST['region2'], 'postalCode' => $_POST['postalCode2'])), 'funding' => array('descriptor' => $_POST['descriptor'], 'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK, 'email' => $_POST['email'], 'mobilePhone' => $_POST['mobilePhone'], 'accountNumber' => $_POST['accountNumber'], 'routingNumber' => $_POST['routingNumber']), 'tosAccepted' => true, 'masterMerchantAccountId' => "qzmnkckz54r94r4f", 'id' => "mc_" . time())); $file = './data/subMerchant.txt'; //[ADD Customer ID to text file] $subMerchantID = $result->merchantAccount->id . "\r\n"; // Write the contents to the file, // using the FILE_APPEND flag to append the content to the end of the file // and the LOCK_EX flag to prevent anyone else writing to the file at the same time file_put_contents($file, $subMerchantID, FILE_APPEND | LOCK_EX); print_r($result); } else { if ($_POST['_act'] == 'CreateTransEscrow') { $result = Braintree_Transaction::sale(array('merchantAccountId' => $_POST["sub_merchant_id"], 'amount' => $_POST["amount"], 'paymentMethodNonce' => $_POST["payment_method_nonce"], 'serviceFeeAmount' => $_POST["serviceFeeAmount"], 'options' => array('holdInEscrow' => true)));
/** * Delete card or PayPal account by token * * @param string $token * @return Braintree_CreditCard | boolean */ public function deletePaymentMethod($token) { try { $ret = Braintree_PaymentMethod::delete($token); $this->_debug($token); $this->_debug($ret); return $ret; } catch (Braintree_Exception $e) { Mage::logException($e); return false; } }