PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/braintree/braintree_php/tests/TestHelper.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 160 lines | 136 code | 23 blank | 1 comment | 4 complexity | 73f591409b162d9b4a0a1017eb9bef82 MD5 | raw file
  1. <?php
  2. set_include_path(
  3. get_include_path() . PATH_SEPARATOR .
  4. realpath(dirname(__FILE__)) . '/../lib'
  5. );
  6. require_once "Braintree.php";
  7. require_once "Braintree/CreditCardNumbers/CardTypeIndicators.php";
  8. require_once "Braintree/CreditCardDefaults.php";
  9. require_once "Braintree/OAuthTestHelper.php";
  10. function integrationMerchantConfig()
  11. {
  12. Braintree_Configuration::environment('development');
  13. Braintree_Configuration::merchantId('integration_merchant_id');
  14. Braintree_Configuration::publicKey('integration_public_key');
  15. Braintree_Configuration::privateKey('integration_private_key');
  16. }
  17. function testMerchantConfig()
  18. {
  19. Braintree_Configuration::environment('development');
  20. Braintree_Configuration::merchantId('test_merchant_id');
  21. Braintree_Configuration::publicKey('test_public_key');
  22. Braintree_Configuration::privateKey('test_private_key');
  23. }
  24. integrationMerchantConfig();
  25. date_default_timezone_set("UTC");
  26. class Braintree_TestHelper
  27. {
  28. public static function defaultMerchantAccountId()
  29. {
  30. return 'sandbox_credit_card';
  31. }
  32. public static function nonDefaultMerchantAccountId()
  33. {
  34. return 'sandbox_credit_card_non_default';
  35. }
  36. public static function nonDefaultSubMerchantAccountId()
  37. {
  38. return 'sandbox_sub_merchant_account';
  39. }
  40. public static function threeDSecureMerchantAccountId()
  41. {
  42. return 'three_d_secure_merchant_account';
  43. }
  44. public static function createViaTr($regularParams, $trParams)
  45. {
  46. $trData = Braintree_TransparentRedirect::transactionData(
  47. array_merge($trParams, array("redirectUrl" => "http://www.example.com"))
  48. );
  49. return Braintree_TestHelper::submitTrRequest(
  50. TransparentRedirect::url(),
  51. $regularParams,
  52. $trData
  53. );
  54. }
  55. public static function submitTrRequest($url, $regularParams, $trData)
  56. {
  57. $curl = curl_init();
  58. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
  59. curl_setopt($curl, CURLOPT_URL, $url);
  60. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
  61. curl_setopt($curl, CURLOPT_HEADER, true);
  62. // curl_setopt($curl, CURLOPT_VERBOSE, true);
  63. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array_merge($regularParams, array('tr_data' => $trData))));
  64. curl_setopt($curl, CURLOPT_HTTPHEADER, array(
  65. 'Content-Type: application/x-www-form-urlencoded'
  66. ));
  67. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  68. $response = curl_exec($curl);
  69. curl_close($curl);
  70. preg_match('/Location: .*\?(.*)/i', $response, $match);
  71. return trim($match[1]);
  72. }
  73. public static function suppressDeprecationWarnings()
  74. {
  75. set_error_handler("Braintree_TestHelper::_errorHandler", E_USER_NOTICE);
  76. }
  77. static function _errorHandler($errno, $errstr, $errfile, $errline)
  78. {
  79. if (preg_match('/^DEPRECATED/', $errstr) == 0) {
  80. trigger_error('Unknown error received: ' . $errstr, E_USER_ERROR);
  81. }
  82. }
  83. public static function includes($collection, $targetItem)
  84. {
  85. foreach ($collection AS $item) {
  86. if ($item->id == $targetItem->id) {
  87. return true;
  88. }
  89. }
  90. return false;
  91. }
  92. public static function assertPrintable($object)
  93. {
  94. " " . $object;
  95. }
  96. public static function settle($transactionId)
  97. {
  98. $http = new Braintree_Http(Braintree_Configuration::$global);
  99. $path = Braintree_Configuration::$global->merchantPath() . '/transactions/' . $transactionId . '/settle';
  100. $http->put($path);
  101. }
  102. public static function settlementDecline($transactionId)
  103. {
  104. $http = new Braintree_Http(Braintree_Configuration::$global);
  105. $path = Braintree_Configuration::$global->merchantPath() . '/transactions/' . $transactionId . '/settlement_decline';
  106. $http->put($path);
  107. }
  108. public static function settlementPending($transactionId)
  109. {
  110. $http = new Braintree_Http(Braintree_Configuration::$global);
  111. $path = Braintree_Configuration::$global->merchantPath() . '/transactions/' . $transactionId . '/settlement_pending';
  112. $http->put($path);
  113. }
  114. public static function escrow($transactionId)
  115. {
  116. $http = new Braintree_Http(Braintree_Configuration::$global);
  117. $path = Braintree_Configuration::$global->merchantPath() . '/transactions/' . $transactionId . '/escrow';
  118. $http->put($path);
  119. }
  120. public static function create3DSVerification($merchantAccountId, $params)
  121. {
  122. $http = new Braintree_Http(Braintree_Configuration::$global);
  123. $path = Braintree_Configuration::$global->merchantPath() . '/three_d_secure/create_verification/' . $merchantAccountId;
  124. $response = $http->post($path, array('threeDSecureVerification' => $params));
  125. return $response['threeDSecureVerification']['threeDSecureToken'];
  126. }
  127. public static function nowInEastern()
  128. {
  129. $eastern = new DateTimeZone('America/New_York');
  130. $now = new DateTime('now', $eastern);
  131. return $now->format('Y-m-d');
  132. }
  133. public static function decodedClientToken($params=array()) {
  134. $encodedClientToken = Braintree_ClientToken::generate($params);
  135. return base64_decode($encodedClientToken);
  136. }
  137. }