本文整理汇总了PHP中Braintree_Transaction::sale方法的典型用法代码示例。如果您正苦于以下问题:PHP Braintree_Transaction::sale方法的具体用法?PHP Braintree_Transaction::sale怎么用?PHP Braintree_Transaction::sale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Braintree_Transaction
的用法示例。
在下文中一共展示了Braintree_Transaction::sale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doDirectPayment
/**
* Submit a payment using Advanced Integration Method
*
* @param array $params assoc array of input parameters for this transaction
*
* @return array the result in a nice formatted array (or an error object)
* @public
*/
function doDirectPayment(&$params)
{
$requestArray = $this->formRequestArray($params);
$result = Braintree_Transaction::sale($requestArray);
if ($result->success) {
$params['trxn_id'] = $result->transaction->id;
$params['gross_amount'] = $result->transaction->amount;
} else {
if ($result->transaction) {
$errormsg = 'Transactions is not approved';
return self::error($result->transaction->processorResponseCode, $result->message);
} else {
$error = "Validation errors:<br/>";
foreach ($result->errors->deepAll() as $e) {
$error .= $e->message;
}
return self::error(9001, $error);
}
}
return $params;
}
示例2: send
public function send()
{
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$amount = $this->currency->format($order_info['total'], $order_info['currency_code'], 1.0, false);
//Load Braintree Library
require_once './vendor/braintree/braintree_php/lib/Braintree.php';
Braintree_Configuration::environment($this->config->get('simple_braintree_payments_mode'));
Braintree_Configuration::merchantId($this->config->get('simple_braintree_payments_merchant'));
Braintree_Configuration::publicKey($this->config->get('simple_braintree_payments_public_key'));
Braintree_Configuration::privateKey($this->config->get('simple_braintree_payments_private_key'));
// Payment nonce received from the client js side
$nonce = $_POST["payment_method_nonce"];
//create object to use as json
$json = array();
$result = null;
try {
// Perform the transaction
$result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodNonce' => $nonce, 'orderId' => $this->session->data['order_id']));
} catch (Exception $e) {
$json['phperror'] = $e->getMessage();
}
$json['details'] = $result;
if ($result->success) {
$this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('simple_braintree_payments_order_status_id'));
$json['success'] = $this->url->link('checkout/success', '', 'SSL');
} else {
$json['error'] = $result->_attributes['message'];
}
$this->response->setOutput(json_encode($json));
}
示例3: braintree
function braintree($data)
{
foreach ($data as $k => $v) {
${$k} = $v;
}
try {
include_once 'config.braintree.php';
$customer = Braintree_Customer::create(['firstName' => $first_name, 'lastName' => $last_name]);
if (!isset($nonce) || empty($nonce)) {
throw new Exception("An unknown error has occurred");
}
if ($customer->success) {
$transaction = Braintree_Transaction::sale(['amount' => $price, 'customerId' => $customer->customer->id, 'paymentMethodNonce' => $nonce]);
if ($transaction->success) {
$this->save($data, __FUNCTION__, $transaction->transaction, 1);
return json_encode(["status" => true, "msg" => sprintf("Your payment has been %s", $transaction->transaction->status)]);
} else {
throw new Exception($transaction->message);
}
}
} catch (Exception $e) {
$this->save($data, __FUNCTION__, (string) $e, 0);
return json_encode(["status" => false, "msg" => $e->getMessage()]);
}
}
示例4: directpay
public function directpay($var = array())
{
$payment = array("amount" => $var['postVal']['amount'], "creditCard" => array("number" => $var['postVal']['ccNum'], "cvv" => $var['postVal']['ccCCV'], "cardholderName" => $var['postVal']['ccHolder'], "expirationMonth" => $var['postVal']['ccExpMM'], "expirationYear" => $var['postVal']['ccExpYY']), "merchantAccountId" => $var['postVal']['cur'], "options" => array("submitForSettlement" => true));
$sale = Braintree_Transaction::sale($payment);
$result = array();
if ($sale->success) {
$result['status'] = "200";
$result['detail']['id'] = $sale->transaction->id;
$result['detail']['sales_id'] = $sale->transaction->id;
$result['detail']['state'] = $sale->transaction->status;
$result['detail']['create_time'] = $sale->transaction->createdAt->format("Y-m-d H:i:s");
$result['detail']['update_time'] = $sale->transaction->updatedAt->format("Y-m-d H:i:s");
$result['detail']['currency'] = $sale->transaction->currencyIsoCode;
$result['detail']['amount'] = $sale->transaction->amount;
$result['detail']['gateway'] = "Braintree";
} else {
if ($sale->transaction) {
$result['status'] = $sale->transaction->processorResponseCode;
$result['errMsg'] = $sale->message;
} else {
$result['status'] = "400";
$errMsg = "";
foreach ($sale->errors->deepAll() as $error) {
$errMsg .= "- " . $error->message . "<br/>";
}
$result['errMsg'] = $errMsg;
}
}
return $result;
}
示例5: donate
function donate($nonce, $info)
{
$result = Braintree_Transaction::sale(['amount' => $info['amount'], 'paymentMethodNonce' => $nonce, 'options' => ['submitForSettlement' => True]]);
if (!isset($result->transaction) || !$result->transaction) {
return $this->processErrors('donation', $result->errors->deepAll());
}
return $this->retrieveTransactioResults($result->success, $result->transaction, $info);
}
示例6: braintreepay
function braintreepay(){
$nonce = $_POST["payment_method_nonce"];
$amount = $_POST["amount"];
$result = Braintree_Transaction::sale([
'amount'=>''.$amount,
'paymentMethodNonce' => 'fake-valid-nonce'
]);
echo $result->success;
}
示例7: _sale
private function _sale($postFormData, $nonce)
{
$amount = $postFormData['Order']['amount'];
$currencyModelObj = ClassRegistry::init('Currency');
$currency = $currencyModelObj->getCurrencyByAbbreviation($postFormData['Order']['currency_abbr']);
$convertedAmount = (double) round($amount / $currency['Currency']['rate'], 2);
$sale = Braintree_Transaction::sale(['amount' => $convertedAmount, 'paymentMethodNonce' => $nonce]);
return $sale;
}
示例8: pay
public function pay($data)
{
global $_SESSION;
$this->debug($_SESSION);
$billingAddress = $this->getAddress($data['billingAddress'], true)[0];
$shippingAddress = $this->getAddress($data['shippingAddress'], true)[0];
$sale = Braintree_Transaction::sale(['amount' => '10.00', 'paymentMethodNonce' => $data['payment_method_nonce'], 'shipping' => ['firstName' => $shippingAddress['address_first_name'], 'lastName' => $shippingAddress['address_last_name'], 'company' => $shippingAddress['address_company_name'], 'streetAddress' => $shippingAddress['address_street'], 'extendedAddress' => $shippingAddress['address_apartment'], 'locality' => $shippingAddress['address_city'], 'region' => $shippingAddress['address_county'], 'postalCode' => $shippingAddress['address_postcode'], 'countryCodeAlpha2' => $shippingAddress['address_country']], 'billing' => ['firstName' => $billingAddress['address_first_name'], 'lastName' => $billingAddress['address_last_name'], 'company' => $billingAddress['address_company_name'], 'streetAddress' => $billingAddress['address_street'], 'extendedAddress' => $billingAddress['address_apartment'], 'locality' => $billingAddress['address_city'], 'region' => $billingAddress['address_county'], 'postalCode' => $billingAddress['address_postcode'], 'countryCodeAlpha2' => $billingAddress['address_country']], 'options' => ['submitForSettlement' => true]]);
return $sale;
}
示例9: _authorize
/**
* Authorizes specified amount
*
* @param Varien_Object $payment
* @param decimal $amount
* @param boolean $capture
* @return Braintree_Payments_Model_Paymentmethod
*/
protected function _authorize(Varien_Object $payment, $amount, $capture, $token = false)
{
try {
$order = $payment->getOrder();
$orderId = $order->getIncrementId();
$billing = $order->getBillingAddress();
$shipping = $order->getShippingAddress();
$transactionParams = array('channel' => $this->_getChannel(), 'orderId' => $orderId, 'amount' => $amount, 'customer' => array('firstName' => $billing->getFirstname(), 'lastName' => $billing->getLastname(), 'company' => $billing->getCompany(), 'phone' => $billing->getTelephone(), 'fax' => $billing->getFax(), 'email' => $order->getCustomerEmail()));
$customerId = Mage::helper('braintree_payments')->generateCustomerId($order->getCustomerId(), $order->getCustomerEmail());
if ($order->getCustomerId() && $this->exists($customerId)) {
$transactionParams['customerId'] = $customerId;
unset($transactionParams['customer']);
} else {
$transactionParams['customer']['id'] = $customerId;
}
if ($capture) {
$transactionParams['options']['submitForSettlement'] = true;
}
if ($this->_merchantAccountId) {
$transactionParams['merchantAccountId'] = $this->_merchantAccountId;
}
$token = $this->_getMethodSpecificAuthorizeTransactionToken($token);
if ($token) {
$nonce = Mage::helper('braintree_payments')->getNonceForVaultedToken($token);
$transactionParams['customerId'] = $customerId;
} else {
$transactionParams['billing'] = $this->_toBraintreeAddress($billing);
$transactionParams['shipping'] = $this->_toBraintreeAddress($shipping);
$transactionParams['options']['addBillingAddressToPaymentMethod'] = true;
$nonce = $payment->getAdditionalInformation('nonce');
}
$transactionParams['paymentMethodNonce'] = $nonce;
$transactionParams = array_merge_recursive($transactionParams, $this->_addMethodSpecificAuthorizeTransactionParams($payment));
if (isset($transactionParams['options']['storeInVault']) && !$transactionParams['options']['storeInVault']) {
$transactionParams['options']['addBillingAddressToPaymentMethod'] = false;
}
$this->_debug($transactionParams);
try {
$result = Braintree_Transaction::sale($transactionParams);
$this->_debug($result);
} catch (Exception $e) {
Mage::logException($e);
Mage::throwException(Mage::helper('braintree_payments')->__('Please try again later'));
}
if ($result->success) {
$this->setStore($payment->getOrder()->getStoreId());
$payment = $this->_processSuccessResult($payment, $result, $amount);
} else {
Mage::throwException(Mage::helper('braintree_payments/error')->parseBraintreeError($result));
}
} catch (Exception $e) {
$this->_processMethodSpecificAuthorizeTransactionError();
throw new Mage_Payment_Model_Info_Exception($e->getMessage());
}
return $this;
}
示例10: quick_transaction
function quick_transaction($cust_id, $token, $amount)
{
$result = Braintree_Transaction::sale(array('amount' => $amount, 'customerId' => $cust_id, 'paymentMethodToken' => $token));
if ($result->success) {
$this->_log_transaction($result->transaction);
return true;
}
// func still running means errors!
$this->_parse_errors($result);
return false;
}
示例11: createTransaction
public function createTransaction($data)
{
Braintree_Configuration::environment($this->config->item('braintree_environment'));
Braintree_Configuration::merchantId($this->config->item('braintree_merchant_id'));
Braintree_Configuration::publicKey($this->config->item('braintree_public_key'));
Braintree_Configuration::privateKey($this->config->item('braintree_private_key'));
$transaction = Braintree_Transaction::sale($data);
if ($transaction) {
return $transaction;
} else {
return false;
}
}
示例12: charge
function charge(&$order)
{
//create a code for the order
if (empty($order->code)) {
$order->code = $order->getRandomCode();
}
//what amount to charge?
$amount = $order->InitialPayment;
//tax
$order->subtotal = $amount;
$tax = $order->getTax(true);
$amount = round((double) $order->subtotal + (double) $tax, 2);
//create a customer
$this->getCustomer($order);
if (empty($this->customer)) {
//failed to create customer
return false;
}
//charge
try {
$response = Braintree_Transaction::sale(array('amount' => $amount, 'customerId' => $this->customer->id));
} catch (Exception $e) {
//$order->status = "error";
$order->errorcode = true;
$order->error = "Error: " . $e->getMessage();
$order->shorterror = $order->error;
return false;
}
if ($response->success) {
//successful charge
$transaction_id = $response->transaction->id;
$response = Braintree_Transaction::submitForSettlement($transaction_id);
if ($response->success) {
$order->payment_transaction_id = $transaction_id;
$order->updateStatus("success");
return true;
} else {
$order->errorcode = true;
$order->error = __("Error during settlement:", "pmpro") . " " . $response->message;
$order->shorterror = $response->message;
return false;
}
} else {
//$order->status = "error";
$order->errorcode = true;
$order->error = __("Error during charge:", "pmpro") . " " . $response->message;
$order->shorterror = $response->message;
return false;
}
}
示例13: singleCharge
/**
* Braintree sale function
* @param bool|true $submitForSettlement
* @param bool|true $storeInVaultOnSuccess
* @return array
*/
public function singleCharge($submitForSettlement = true, $storeInVaultOnSuccess = true)
{
$this->options['options']['submitForSettlement'] = $submitForSettlement;
$this->options['options']['storeInVaultOnSuccess'] = $storeInVaultOnSuccess;
$result = \Braintree_Transaction::sale($this->options);
if ($result->success) {
return ['status' => true, 'result' => $result];
} else {
if ($result->transaction) {
return ['status' => false, 'result' => $result];
} else {
return ['status' => false, 'result' => $result];
}
}
}
示例14: authorize
/**
* After form has been submitted, send CC details to Braintree and ensure the card is going to work
* If not, void the validation result (processed elsewhere) and have the submit the form again
*
* @param $feed - Current configured payment feed
* @param $submission_data - Contains form field data submitted by the user as well as payment information (i.e. payment amount, setup fee, line items, etc...)
* @param $form - Current form array containing all form settings
* @param $entry - Current entry array containing entry information (i.e data submitted by users). NOTE: the entry hasn't been saved to the database at this point, so this $entry object does not have the "ID" property and is only a memory representation of the entry.
* @return array - Return an $authorization array in the following format:
* [
* "is_authorized" => true|false,
* "error_message" => "Error message",
* "transaction_id" => "XXX",
*
* //If the payment is captured in this method, return a "captured_payment" array with the following information about the payment
* "captured_payment" => ["is_success"=>true|false, "error_message" => "error message", "transaction_id" => "xxx", "amount" => 20]
* ]
* @since 1.0
* @return void
*/
protected function authorize($feed, $submission_data, $form, $entry)
{
// Prepare authorization response payload
$authorization = array('is_authorized' => false, 'error_message' => apply_filters('gform_braintree_credit_card_failure_message', __('Your card could not be billed. Please ensure the details you entered are correct and try again.', 'gravity-forms-braintree')), 'transaction_id' => '', 'captured_payment' => array('is_success' => false, 'error_message' => '', 'transaction_id' => '', 'amount' => $submission_data['payment_amount']));
// Perform capture in this function. For this version, we won't authorize and then capture later
// at least, not in this version
if ($settings = $this->get_plugin_settings()) {
// Sanitize card number, removing dashes and spaces
$card_number = str_replace(array('-', ' '), '', $submission_data['card_number']);
// Prepare Braintree payload
$args = array('amount' => $submission_data['payment_amount'], 'creditCard' => array('number' => $card_number, 'expirationDate' => sprintf('%s/%s', $submission_data['card_expiration_date'][0], $submission_data['card_expiration_date'][1]), 'cardholderName' => $submission_data['card_name'], 'cvv' => $submission_data['card_security_code']));
try {
// Configure Braintree environment
Braintree_Configuration::environment(strtolower($settings['environment']));
Braintree_Configuration::merchantId($settings['merchant-id']);
Braintree_Configuration::publicKey($settings['public-key']);
Braintree_Configuration::privateKey($settings['private-key']);
// Set to auto settlemt if applicable
if ($settings['settlement'] == 'Yes') {
$args['options']['submitForSettlement'] = 'true';
}
// Send transaction to Braintree
$result = Braintree_Transaction::sale($args);
// Update response to reflect successful payment
if ($result->success == '1') {
$authorization['is_authorized'] = true;
$authorization['error_message'] = '';
$authorization['transaction_id'] = $result->transaction->_attributes['id'];
$authorization['captured_payment'] = array('is_success' => true, 'transaction_id' => $result->transaction->_attributes['id'], 'amount' => $result->transaction->_attributes['amount'], 'error_message' => '', 'payment_method' => 'Credit Card');
} else {
// Append gateway response text to error message if it exists. If it doesn't exist, a more hardcore
// failure has occured and it won't do the user any good to see it other than a general error message
if (isset($result->_attributes['transaction']->_attributes['processorResponseText'])) {
$authorization['error_message'] .= sprintf('. Your bank said: %s.', $result->_attributes['transaction']->_attributes['processorResponseText']);
}
}
} catch (Exception $e) {
// Do nothing with exception object, just fallback to generic failure
}
return $authorization;
}
return false;
}
示例15: purchase
/**
* Purchase
* @param $payment
* @param $device_data
* @return Braintree_Result_Successful
*/
public function purchase($payment, $device_data)
{
$this->payment_data = ['amount' => (string) $payment['amount'], 'merchantAccountId' => $payment['merchantAccountId'], 'orderId' => $payment['orderId'], 'paymentMethodNonce' => $payment['payment_nonce'], 'customer' => $payment['customer'], 'shipping' => $payment['shipping'], 'billing' => $payment['billing'], 'options' => $payment['options'], 'deviceData' => $device_data];
/**
* Custom fields
*/
if (!empty($payment['party_id'])) {
$this->payment_data['customFields'] = ['party_id' => $payment['party_id']];
}
/**
* 5 digit zip code for US
*/
if ($this->payment_data['billing']['countryCodeAlpha2'] == 'us' && strpos($this->payment_data['billing']['postalCode'], '-')) {
$zip = explode('-', $this->payment_data['billing']['postalCode']);
$this->payment_data['billing']['postalCode'] = $zip[0];
}
if ($this->payment_data['shipping']['countryCodeAlpha2'] == 'us' && strpos($this->payment_data['shipping']['postalCode'], '-')) {
$s_zip = explode('-', $this->payment_data['shipping']['postalCode']);
$this->payment_data['shipping']['postalCode'] = $s_zip[0];
}
return Braintree_Transaction::sale($this->payment_data);
}