/wp-content/plugins/woocommerce-gateway-paypal-powered-by-braintree/braintree_sdk/lib/Braintree/Result/Error.php

https://gitlab.com/hunt9310/ras · PHP · 124 lines · 66 code · 10 blank · 48 comment · 14 complexity · 25a7b61a9858d76fff5135ab0fbca261 MD5 · raw file

  1. <?php
  2. namespace Braintree\Result;
  3. use Braintree\Base;
  4. use Braintree\Transaction;
  5. use Braintree\Subscription;
  6. use Braintree\MerchantAccount;
  7. use Braintree\Util;
  8. use Braintree\Error\ErrorCollection;
  9. /**
  10. * Braintree Error Result
  11. *
  12. * An Error Result will be returned from gateway methods when
  13. * the gateway responds with an error. It will provide access
  14. * to the original request.
  15. * For example, when voiding a transaction, Error Result will
  16. * respond to the void request if it failed:
  17. *
  18. * <code>
  19. * $result = Transaction::void('abc123');
  20. * if ($result->success) {
  21. * // Successful Result
  22. * } else {
  23. * // Result\Error
  24. * }
  25. * </code>
  26. *
  27. * @package Braintree
  28. * @subpackage Result
  29. * @copyright 2015 Braintree, a division of PayPal, Inc.
  30. *
  31. * @property-read array $params original passed params
  32. * @property-read Braintree\Error\ErrorCollection $errors
  33. * @property-read Braintree\Result\CreditCardVerification $creditCardVerification credit card verification data
  34. */
  35. class Error extends Base
  36. {
  37. /**
  38. * @var bool always false
  39. */
  40. public $success = false;
  41. /**
  42. * return original value for a field
  43. * For example, if a user tried to submit 'invalid-email' in the html field transaction[customer][email],
  44. * $result->valueForHtmlField("transaction[customer][email]") would yield "invalid-email"
  45. *
  46. * @param string $field
  47. * @return string
  48. */
  49. public function valueForHtmlField($field)
  50. {
  51. $pieces = preg_split("/[\[\]]+/", $field, 0, PREG_SPLIT_NO_EMPTY);
  52. $params = $this->params;
  53. foreach(array_slice($pieces, 0, -1) as $key) {
  54. $params = $params[Util::delimiterToCamelCase($key)];
  55. }
  56. if ($key != 'custom_fields') {
  57. $finalKey = Util::delimiterToCamelCase(end($pieces));
  58. } else {
  59. $finalKey = end($pieces);
  60. }
  61. $fieldValue = isset($params[$finalKey]) ? $params[$finalKey] : null;
  62. return $fieldValue;
  63. }
  64. /**
  65. * overrides default constructor
  66. * @ignore
  67. * @param array $response gateway response array
  68. */
  69. public function __construct($response)
  70. {
  71. $this->_attributes = $response;
  72. $this->_set('errors', new ErrorCollection($response['errors']));
  73. if(isset($response['verification'])) {
  74. $this->_set('creditCardVerification', new CreditCardVerification($response['verification']));
  75. } else {
  76. $this->_set('creditCardVerification', null);
  77. }
  78. if(isset($response['transaction'])) {
  79. $this->_set('transaction', Transaction::factory($response['transaction']));
  80. } else {
  81. $this->_set('transaction', null);
  82. }
  83. if(isset($response['subscription'])) {
  84. $this->_set('subscription', Subscription::factory($response['subscription']));
  85. } else {
  86. $this->_set('subscription', null);
  87. }
  88. if(isset($response['merchantAccount'])) {
  89. $this->_set('merchantAccount', MerchantAccount::factory($response['merchantAccount']));
  90. } else {
  91. $this->_set('merchantAccount', null);
  92. }
  93. if(isset($response['verification'])) {
  94. $this->_set('verification', new CreditCardVerification($response['verification']));
  95. } else {
  96. $this->_set('verification', null);
  97. }
  98. }
  99. /**
  100. * create a printable representation of the object as:
  101. * ClassName[property=value, property=value]
  102. * @ignore
  103. * @return string
  104. */
  105. public function __toString()
  106. {
  107. $output = Util::attributesToString($this->_attributes);
  108. if (isset($this->_creditCardVerification)) {
  109. $output .= sprintf('%s', $this->_creditCardVerification);
  110. }
  111. return __CLASS__ .'[' . $output . ']';
  112. }
  113. }
  114. class_alias('Braintree\Result\Error', 'Braintree_Result_Error');