BraintreeTransaction

Braintree Transaction processor Creates and manages transactions.

Defined (1)

The class is defined in the following location(s).

/classes/lib/Braintree/Braintree/Transaction.php  
  1. final class Transaction extends Base 
  2. // Transaction Status 
  3. const AUTHORIZATION_EXPIRED = 'authorization_expired'; 
  4. const AUTHORIZING = 'authorizing'; 
  5. const AUTHORIZED = 'authorized'; 
  6. const GATEWAY_REJECTED = 'gateway_rejected'; 
  7. const FAILED = 'failed'; 
  8. const PROCESSOR_DECLINED = 'processor_declined'; 
  9. const SETTLED = 'settled'; 
  10. const SETTLING = 'settling'; 
  11. const SUBMITTED_FOR_SETTLEMENT = 'submitted_for_settlement'; 
  12. const VOIDED = 'voided'; 
  13. const UNRECOGNIZED = 'unrecognized'; 
  14. const SETTLEMENT_DECLINED = 'settlement_declined'; 
  15. const SETTLEMENT_PENDING = 'settlement_pending'; 
  16. const SETTLEMENT_CONFIRMED = 'settlement_confirmed'; 
  17.  
  18. // Transaction Escrow Status 
  19. const ESCROW_HOLD_PENDING = 'hold_pending'; 
  20. const ESCROW_HELD = 'held'; 
  21. const ESCROW_RELEASE_PENDING = 'release_pending'; 
  22. const ESCROW_RELEASED = 'released'; 
  23. const ESCROW_REFUNDED = 'refunded'; 
  24.  
  25. // Transaction Types 
  26. const SALE = 'sale'; 
  27. const CREDIT = 'credit'; 
  28.  
  29. // Transaction Created Using 
  30. const FULL_INFORMATION = 'full_information'; 
  31. const TOKEN = 'token'; 
  32.  
  33. // Transaction Sources 
  34. const API = 'api'; 
  35. const CONTROL_PANEL = 'control_panel'; 
  36. const RECURRING = 'recurring'; 
  37.  
  38. // Gateway Rejection Reason 
  39. const AVS = 'avs'; 
  40. const AVS_AND_CVV = 'avs_and_cvv'; 
  41. const CVV = 'cvv'; 
  42. const DUPLICATE = 'duplicate'; 
  43. const FRAUD = 'fraud'; 
  44. const THREE_D_SECURE = 'three_d_secure'; 
  45. const APPLICATION_INCOMPLETE = 'application_incomplete'; 
  46.  
  47. // Industry Types 
  48. const LODGING_INDUSTRY = 'lodging'; 
  49. const TRAVEL_AND_CRUISE_INDUSTRY = 'travel_cruise'; 
  50.  
  51. /** 
  52. * sets instance properties from an array of values 
  53. * @ignore 
  54. * @access protected 
  55. * @param array $transactionAttribs array of transaction data 
  56. * @return void 
  57. */ 
  58. protected function _initialize($transactionAttribs) 
  59. $this->_attributes = $transactionAttribs; 
  60.  
  61. if (isset($transactionAttribs['applePay'])) { 
  62. $this->_set('applePayCardDetails',  
  63. new Transaction\ApplePayCardDetails( 
  64. $transactionAttribs['applePay'] 
  65. ); 
  66.  
  67. if (isset($transactionAttribs['androidPayCard'])) { 
  68. $this->_set('androidPayCardDetails',  
  69. new Transaction\AndroidPayCardDetails( 
  70. $transactionAttribs['androidPayCard'] 
  71. ); 
  72.  
  73. if (isset($transactionAttribs['amexExpressCheckoutCard'])) { 
  74. $this->_set('amexExpressCheckoutCardDetails',  
  75. new Transaction\AmexExpressCheckoutCardDetails( 
  76. $transactionAttribs['amexExpressCheckoutCard'] 
  77. ); 
  78.  
  79. if (isset($transactionAttribs['venmoAccount'])) { 
  80. $this->_set('venmoAccountDetails',  
  81. new Transaction\VenmoAccountDetails( 
  82. $transactionAttribs['venmoAccount'] 
  83. ); 
  84.  
  85. if (isset($transactionAttribs['creditCard'])) { 
  86. $this->_set('creditCardDetails',  
  87. new Transaction\CreditCardDetails( 
  88. $transactionAttribs['creditCard'] 
  89. ); 
  90.  
  91. if (isset($transactionAttribs['coinbaseAccount'])) { 
  92. $this->_set('coinbaseDetails',  
  93. new Transaction\CoinbaseDetails( 
  94. $transactionAttribs['coinbaseAccount'] 
  95. ); 
  96.  
  97. if (isset($transactionAttribs['europeBankAccount'])) { 
  98. $this->_set('europeBankAccount',  
  99. new Transaction\EuropeBankAccountDetails( 
  100. $transactionAttribs['europeBankAccount'] 
  101. ); 
  102.  
  103. if (isset($transactionAttribs['paypal'])) { 
  104. $this->_set('paypalDetails',  
  105. new Transaction\PayPalDetails( 
  106. $transactionAttribs['paypal'] 
  107. ); 
  108.  
  109. if (isset($transactionAttribs['customer'])) { 
  110. $this->_set('customerDetails',  
  111. new Transaction\CustomerDetails( 
  112. $transactionAttribs['customer'] 
  113. ); 
  114.  
  115. if (isset($transactionAttribs['billing'])) { 
  116. $this->_set('billingDetails',  
  117. new Transaction\AddressDetails( 
  118. $transactionAttribs['billing'] 
  119. ); 
  120.  
  121. if (isset($transactionAttribs['shipping'])) { 
  122. $this->_set('shippingDetails',  
  123. new Transaction\AddressDetails( 
  124. $transactionAttribs['shipping'] 
  125. ); 
  126.  
  127. if (isset($transactionAttribs['subscription'])) { 
  128. $this->_set('subscriptionDetails',  
  129. new Transaction\SubscriptionDetails( 
  130. $transactionAttribs['subscription'] 
  131. ); 
  132.  
  133. if (isset($transactionAttribs['descriptor'])) { 
  134. $this->_set('descriptor',  
  135. new Descriptor( 
  136. $transactionAttribs['descriptor'] 
  137. ); 
  138.  
  139. if (isset($transactionAttribs['disbursementDetails'])) { 
  140. $this->_set('disbursementDetails',  
  141. new DisbursementDetails($transactionAttribs['disbursementDetails']) 
  142. ); 
  143.  
  144. $disputes = []; 
  145. if (isset($transactionAttribs['disputes'])) { 
  146. foreach ($transactionAttribs['disputes'] AS $dispute) { 
  147. $disputes[] = Dispute::factory($dispute); 
  148.  
  149. $this->_set('disputes', $disputes); 
  150.  
  151. $statusHistory = []; 
  152. if (isset($transactionAttribs['statusHistory'])) { 
  153. foreach ($transactionAttribs['statusHistory'] AS $history) { 
  154. $statusHistory[] = new Transaction\StatusDetails($history); 
  155.  
  156. $this->_set('statusHistory', $statusHistory); 
  157.  
  158. $addOnArray = []; 
  159. if (isset($transactionAttribs['addOns'])) { 
  160. foreach ($transactionAttribs['addOns'] AS $addOn) { 
  161. $addOnArray[] = AddOn::factory($addOn); 
  162. $this->_set('addOns', $addOnArray); 
  163.  
  164. $discountArray = []; 
  165. if (isset($transactionAttribs['discounts'])) { 
  166. foreach ($transactionAttribs['discounts'] AS $discount) { 
  167. $discountArray[] = Discount::factory($discount); 
  168. $this->_set('discounts', $discountArray); 
  169.  
  170. if(isset($transactionAttribs['riskData'])) { 
  171. $this->_set('riskData', RiskData::factory($transactionAttribs['riskData'])); 
  172. if(isset($transactionAttribs['threeDSecureInfo'])) { 
  173. $this->_set('threeDSecureInfo', ThreeDSecureInfo::factory($transactionAttribs['threeDSecureInfo'])); 
  174. if(isset($transactionAttribs['facilitatorDetails'])) { 
  175. $this->_set('facilitatorDetails', FacilitatorDetails::factory($transactionAttribs['facilitatorDetails'])); 
  176.  
  177. /** 
  178. * returns a string representation of the transaction 
  179. * @return string 
  180. */ 
  181. public function __toString() 
  182. // array of attributes to print 
  183. $display = [ 
  184. 'id', 'type', 'amount', 'status',  
  185. 'createdAt', 'creditCardDetails', 'customerDetails' 
  186. ]; 
  187.  
  188. $displayAttributes = []; 
  189. foreach ($display AS $attrib) { 
  190. $displayAttributes[$attrib] = $this->$attrib; 
  191. return __CLASS__ . '[' . 
  192. Util::attributesToString($displayAttributes) .']'; 
  193.  
  194. public function isEqual($otherTx) 
  195. return $this->id === $otherTx->id; 
  196.  
  197. public function vaultCreditCard() 
  198. $token = $this->creditCardDetails->token; 
  199. if (empty($token)) { 
  200. return null; 
  201. else { 
  202. return CreditCard::find($token); 
  203.  
  204. /** @return void|Braintree\Customer */ 
  205. public function vaultCustomer() 
  206. $customerId = $this->customerDetails->id; 
  207. if (empty($customerId)) { 
  208. return null; 
  209. else { 
  210. return Customer::find($customerId); 
  211.  
  212. /** @return bool */ 
  213. public function isDisbursed() { 
  214. return $this->disbursementDetails->isValid(); 
  215.  
  216. /** 
  217. * factory method: returns an instance of Transaction 
  218. * to the requesting method, with populated properties 
  219. * @ignore 
  220. * @return Transaction 
  221. */ 
  222. public static function factory($attributes) 
  223. $instance = new self(); 
  224. $instance->_initialize($attributes); 
  225. return $instance; 
  226.  
  227.  
  228. // static methods redirecting to gateway 
  229.  
  230. public static function cloneTransaction($transactionId, $attribs) 
  231. return Configuration::gateway()->transaction()->cloneTransaction($transactionId, $attribs); 
  232.  
  233. public static function createFromTransparentRedirect($queryString) 
  234. return Configuration::gateway()->transaction()->createFromTransparentRedirect($queryString); 
  235.  
  236. public static function createTransactionUrl() 
  237. return Configuration::gateway()->transaction()->createTransactionUrl(); 
  238.  
  239. public static function credit($attribs) 
  240. return Configuration::gateway()->transaction()->credit($attribs); 
  241.  
  242. public static function creditNoValidate($attribs) 
  243. return Configuration::gateway()->transaction()->creditNoValidate($attribs); 
  244.  
  245. public static function find($id) 
  246. return Configuration::gateway()->transaction()->find($id); 
  247.  
  248. public static function sale($attribs) 
  249. return Configuration::gateway()->transaction()->sale($attribs); 
  250.  
  251. public static function saleNoValidate($attribs) 
  252. return Configuration::gateway()->transaction()->saleNoValidate($attribs); 
  253.  
  254. public static function search($query) 
  255. return Configuration::gateway()->transaction()->search($query); 
  256.  
  257. public static function fetch($query, $ids) 
  258. return Configuration::gateway()->transaction()->fetch($query, $ids); 
  259.  
  260. public static function void($transactionId) 
  261. return Configuration::gateway()->transaction()->void($transactionId); 
  262.  
  263. public static function voidNoValidate($transactionId) 
  264. return Configuration::gateway()->transaction()->voidNoValidate($transactionId); 
  265.  
  266. public static function submitForSettlement($transactionId, $amount = null, $attribs = []) 
  267. return Configuration::gateway()->transaction()->submitForSettlement($transactionId, $amount, $attribs); 
  268.  
  269. public static function submitForSettlementNoValidate($transactionId, $amount = null, $attribs = []) 
  270. return Configuration::gateway()->transaction()->submitForSettlementNoValidate($transactionId, $amount, $attribs); 
  271.  
  272. public static function submitForPartialSettlement($transactionId, $amount, $attribs = []) 
  273. return Configuration::gateway()->transaction()->submitForPartialSettlement($transactionId, $amount, $attribs); 
  274.  
  275. public static function holdInEscrow($transactionId) 
  276. return Configuration::gateway()->transaction()->holdInEscrow($transactionId); 
  277.  
  278. public static function releaseFromEscrow($transactionId) 
  279. return Configuration::gateway()->transaction()->releaseFromEscrow($transactionId); 
  280.  
  281. public static function cancelRelease($transactionId) 
  282. return Configuration::gateway()->transaction()->cancelRelease($transactionId); 
  283.  
  284. public static function refund($transactionId, $amount = null) 
  285. return Configuration::gateway()->transaction()->refund($transactionId, $amount);