MerchantAccountTest.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. <?php
  2. namespace Test\Integration;
  3. require_once dirname(__DIR__) . '/Setup.php';
  4. use Test;
  5. use Test\Setup;
  6. use Braintree;
  7. class MerchantAccountTest extends Setup
  8. {
  9. private static $deprecatedValidParams = [
  10. 'applicantDetails' => [
  11. 'companyName' => "Robot City",
  12. 'firstName' => "Joe",
  13. 'lastName' => "Bloggs",
  14. 'email' => "joe@bloggs.com",
  15. 'phone' => "555-555-5555",
  16. 'address' => [
  17. 'streetAddress' => "123 Credibility St.",
  18. 'postalCode' => "60606",
  19. 'locality' => "Chicago",
  20. 'region' => "IL",
  21. ],
  22. 'dateOfBirth' => "10/9/1980",
  23. 'ssn' => "123-00-1234",
  24. 'taxId' => "123456789",
  25. 'routingNumber' => "122100024",
  26. 'accountNumber' => "43759348798"
  27. ],
  28. 'tosAccepted' => true,
  29. 'masterMerchantAccountId' => "sandbox_master_merchant_account"
  30. ];
  31. private static $validParams = [
  32. 'individual' => [
  33. 'firstName' => "Joe",
  34. 'lastName' => "Bloggs",
  35. 'email' => "joe@bloggs.com",
  36. 'phone' => "555-555-5555",
  37. 'address' => [
  38. 'streetAddress' => "123 Credibility St.",
  39. 'postalCode' => "60606",
  40. 'locality' => "Chicago",
  41. 'region' => "IL",
  42. ],
  43. 'dateOfBirth' => "10/9/1980",
  44. 'ssn' => "123-00-1234",
  45. ],
  46. 'business' => [
  47. 'dbaName' => "Robot City",
  48. 'legalName' => "Robot City INC",
  49. 'taxId' => "123456789",
  50. ],
  51. 'funding' => [
  52. 'routingNumber' => "122100024",
  53. 'accountNumber' => "43759348798",
  54. 'destination' => Braintree\MerchantAccount::FUNDING_DESTINATION_BANK,
  55. 'descriptor' => 'Joes Bloggs MI',
  56. ],
  57. 'tosAccepted' => true,
  58. 'masterMerchantAccountId' => "sandbox_master_merchant_account"
  59. ];
  60. public function testCreate()
  61. {
  62. $result = Braintree\MerchantAccount::create(self::$validParams);
  63. $this->assertEquals(true, $result->success);
  64. $merchantAccount = $result->merchantAccount;
  65. $this->assertEquals(Braintree\MerchantAccount::STATUS_PENDING, $merchantAccount->status);
  66. $this->assertEquals("sandbox_master_merchant_account", $merchantAccount->masterMerchantAccount->id);
  67. }
  68. public function testGatewayCreate()
  69. {
  70. $gateway = new Braintree\Gateway([
  71. 'environment' => 'development',
  72. 'merchantId' => 'integration_merchant_id',
  73. 'publicKey' => 'integration_public_key',
  74. 'privateKey' => 'integration_private_key'
  75. ]);
  76. $result = $gateway->merchantAccount()->create(self::$validParams);
  77. $this->assertEquals(true, $result->success);
  78. $merchantAccount = $result->merchantAccount;
  79. $this->assertEquals(Braintree\MerchantAccount::STATUS_PENDING, $merchantAccount->status);
  80. $this->assertEquals("sandbox_master_merchant_account", $merchantAccount->masterMerchantAccount->id);
  81. }
  82. public function testCreateWithDeprecatedParameters()
  83. {
  84. Test\Helper::suppressDeprecationWarnings();
  85. $result = Braintree\MerchantAccount::create(self::$deprecatedValidParams);
  86. $this->assertEquals(true, $result->success);
  87. $merchantAccount = $result->merchantAccount;
  88. $this->assertEquals(Braintree\MerchantAccount::STATUS_PENDING, $merchantAccount->status);
  89. $this->assertEquals("sandbox_master_merchant_account", $merchantAccount->masterMerchantAccount->id);
  90. }
  91. public function testCreateWithId()
  92. {
  93. $rand = rand(1, 1000);
  94. $subMerchantAccountId = "sub_merchant_account_id" + $rand;
  95. $validParamsWithId = array_merge([], self::$validParams);
  96. $validParamsWithId['id'] = $subMerchantAccountId;
  97. $result = Braintree\MerchantAccount::create($validParamsWithId);
  98. $this->assertEquals(true, $result->success);
  99. $merchantAccount = $result->merchantAccount;
  100. $this->assertEquals(Braintree\MerchantAccount::STATUS_PENDING, $merchantAccount->status);
  101. $this->assertEquals("sandbox_master_merchant_account", $merchantAccount->masterMerchantAccount->id);
  102. $this->assertEquals("sub_merchant_account_id" + $rand, $merchantAccount->id);
  103. }
  104. public function testFailedCreate()
  105. {
  106. $result = Braintree\MerchantAccount::create([]);
  107. $this->assertEquals(false, $result->success);
  108. $errors = $result->errors->forKey('merchantAccount')->onAttribute('masterMerchantAccountId');
  109. $this->assertEquals(Braintree\Error\Codes::MERCHANT_ACCOUNT_MASTER_MERCHANT_ACCOUNT_ID_IS_REQUIRED, $errors[0]->code);
  110. }
  111. public function testCreateWithFundingDestination()
  112. {
  113. $params = array_merge([], self::$validParams);
  114. $params['funding']['destination'] = Braintree\MerchantAccount::FUNDING_DESTINATION_BANK;
  115. $result = Braintree\MerchantAccount::create($params);
  116. $this->assertEquals(true, $result->success);
  117. $params = array_merge([], self::$validParams);
  118. $params['funding']['destination'] = Braintree\MerchantAccount::FUNDING_DESTINATION_EMAIL;
  119. $params['funding']['email'] = "billgates@outlook.com";
  120. $result = Braintree\MerchantAccount::create($params);
  121. $this->assertEquals(true, $result->success);
  122. $params = array_merge([], self::$validParams);
  123. $params['funding']['destination'] = Braintree\MerchantAccount::FUNDING_DESTINATION_MOBILE_PHONE;
  124. $params['funding']['mobilePhone'] = "1112224444";
  125. $result = Braintree\MerchantAccount::create($params);
  126. $this->assertEquals(true, $result->success);
  127. }
  128. public function testFind()
  129. {
  130. $params = array_merge([], self::$validParams);
  131. $result = Braintree\MerchantAccount::create(self::$validParams);
  132. $this->assertEquals(true, $result->success);
  133. $this->assertEquals(Braintree\MerchantAccount::STATUS_PENDING, $result->merchantAccount->status);
  134. $id = $result->merchantAccount->id;
  135. $merchantAccount = Braintree\MerchantAccount::find($id);
  136. $this->assertEquals(Braintree\MerchantAccount::STATUS_ACTIVE, $merchantAccount->status);
  137. $this->assertEquals($params['individual']['firstName'], $merchantAccount->individualDetails->firstName);
  138. $this->assertEquals($params['individual']['lastName'], $merchantAccount->individualDetails->lastName);
  139. }
  140. public function testRetrievesMasterMerchantAccountCurrencyIsoCode()
  141. {
  142. $merchantAccount = Braintree\MerchantAccount::find("sandbox_master_merchant_account");
  143. $this->assertEquals("USD", $merchantAccount->currencyIsoCode);
  144. }
  145. public function testFind_throwsIfNotFound()
  146. {
  147. $this->setExpectedException('Braintree\Exception\NotFound', 'merchant account with id does-not-exist not found');
  148. Braintree\MerchantAccount::find('does-not-exist');
  149. }
  150. public function testUpdate()
  151. {
  152. $params = array_merge([], self::$validParams);
  153. unset($params["tosAccepted"]);
  154. unset($params["masterMerchantAccountId"]);
  155. $params["individual"]["firstName"] = "John";
  156. $params["individual"]["lastName"] = "Doe";
  157. $params["individual"]["email"] = "john.doe@example.com";
  158. $params["individual"]["dateOfBirth"] = "1970-01-01";
  159. $params["individual"]["phone"] = "3125551234";
  160. $params["individual"]["address"]["streetAddress"] = "123 Fake St";
  161. $params["individual"]["address"]["locality"] = "Chicago";
  162. $params["individual"]["address"]["region"] = "IL";
  163. $params["individual"]["address"]["postalCode"] = "60622";
  164. $params["business"]["dbaName"] = "James's Bloggs";
  165. $params["business"]["legalName"] = "James's Bloggs Inc";
  166. $params["business"]["taxId"] = "123456789";
  167. $params["business"]["address"]["streetAddress"] = "999 Fake St";
  168. $params["business"]["address"]["locality"] = "Miami";
  169. $params["business"]["address"]["region"] = "FL";
  170. $params["business"]["address"]["postalCode"] = "99999";
  171. $params["funding"]["accountNumber"] = "43759348798";
  172. $params["funding"]["routingNumber"] = "071000013";
  173. $params["funding"]["email"] = "check@this.com";
  174. $params["funding"]["mobilePhone"] = "1234567890";
  175. $params["funding"]["destination"] = Braintree\MerchantAccount::FUNDING_DESTINATION_BANK;
  176. $params["funding"]["descriptor"] = "Joes Bloggs FL";
  177. $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
  178. $this->assertEquals(true, $result->success);
  179. $updatedMerchantAccount = $result->merchantAccount;
  180. $this->assertEquals("active", $updatedMerchantAccount->status);
  181. $this->assertEquals("sandbox_sub_merchant_account", $updatedMerchantAccount->id);
  182. $this->assertEquals("sandbox_master_merchant_account", $updatedMerchantAccount->masterMerchantAccount->id);
  183. $this->assertEquals("John", $updatedMerchantAccount->individualDetails->firstName);
  184. $this->assertEquals("Doe", $updatedMerchantAccount->individualDetails->lastName);
  185. $this->assertEquals("john.doe@example.com", $updatedMerchantAccount->individualDetails->email);
  186. $this->assertEquals("1970-01-01", $updatedMerchantAccount->individualDetails->dateOfBirth);
  187. $this->assertEquals("3125551234", $updatedMerchantAccount->individualDetails->phone);
  188. $this->assertEquals("123 Fake St", $updatedMerchantAccount->individualDetails->addressDetails->streetAddress);
  189. $this->assertEquals("Chicago", $updatedMerchantAccount->individualDetails->addressDetails->locality);
  190. $this->assertEquals("IL", $updatedMerchantAccount->individualDetails->addressDetails->region);
  191. $this->assertEquals("60622", $updatedMerchantAccount->individualDetails->addressDetails->postalCode);
  192. $this->assertEquals("James's Bloggs", $updatedMerchantAccount->businessDetails->dbaName);
  193. $this->assertEquals("James's Bloggs Inc", $updatedMerchantAccount->businessDetails->legalName);
  194. $this->assertEquals("123456789", $updatedMerchantAccount->businessDetails->taxId);
  195. $this->assertEquals("999 Fake St", $updatedMerchantAccount->businessDetails->addressDetails->streetAddress);
  196. $this->assertEquals("Miami", $updatedMerchantAccount->businessDetails->addressDetails->locality);
  197. $this->assertEquals("FL", $updatedMerchantAccount->businessDetails->addressDetails->region);
  198. $this->assertEquals("99999", $updatedMerchantAccount->businessDetails->addressDetails->postalCode);
  199. $this->assertEquals("8798", $updatedMerchantAccount->fundingDetails->accountNumberLast4);
  200. $this->assertEquals("071000013", $updatedMerchantAccount->fundingDetails->routingNumber);
  201. $this->assertEquals("check@this.com", $updatedMerchantAccount->fundingDetails->email);
  202. $this->assertEquals("1234567890", $updatedMerchantAccount->fundingDetails->mobilePhone);
  203. $this->assertEquals(Braintree\MerchantAccount::FUNDING_DESTINATION_BANK, $updatedMerchantAccount->fundingDetails->destination);
  204. $this->assertEquals("Joes Bloggs FL", $updatedMerchantAccount->fundingDetails->descriptor);
  205. }
  206. public function testUpdateDoesNotRequireAllFields()
  207. {
  208. $params = [
  209. 'individual' => [
  210. 'firstName' => "Joe"
  211. ]
  212. ];
  213. $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
  214. $this->assertEquals(true, $result->success);
  215. }
  216. public function testUpdateWithBlankFields()
  217. {
  218. $params = [
  219. 'individual' => [
  220. 'firstName' => "",
  221. 'lastName' => "",
  222. 'email' => "",
  223. 'phone' => "",
  224. 'address' => [
  225. 'streetAddress' => "",
  226. 'postalCode' => "",
  227. 'locality' => "",
  228. 'region' => "",
  229. ],
  230. 'dateOfBirth' => "",
  231. 'ssn' => "",
  232. ],
  233. 'business' => [
  234. 'dbaName' => "",
  235. 'legalName' => "",
  236. 'taxId' => "",
  237. ],
  238. 'funding' => [
  239. 'routingNumber' => "",
  240. 'accountNumber' => "",
  241. 'destination' => "",
  242. ],
  243. ];
  244. $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
  245. $this->assertEquals(false, $result->success);
  246. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("firstName");
  247. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_FIRST_NAME_IS_REQUIRED);
  248. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("lastName");
  249. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_LAST_NAME_IS_REQUIRED);
  250. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("dateOfBirth");
  251. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_DATE_OF_BIRTH_IS_REQUIRED);
  252. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("email");
  253. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_EMAIL_IS_REQUIRED);
  254. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("streetAddress");
  255. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_STREET_ADDRESS_IS_REQUIRED);
  256. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("postalCode");
  257. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_POSTAL_CODE_IS_REQUIRED);
  258. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("locality");
  259. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_LOCALITY_IS_REQUIRED);
  260. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("region");
  261. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_REGION_IS_REQUIRED);
  262. $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("destination");
  263. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_DESTINATION_IS_REQUIRED);
  264. }
  265. public function testUpdateWithInvalidFields()
  266. {
  267. $params = [
  268. "individual" => [
  269. "firstName" => "<>",
  270. "lastName" => "<>",
  271. "email" => "bad",
  272. "phone" => "999",
  273. "address" => [
  274. "streetAddress" => "nope",
  275. "postalCode" => "1",
  276. "region" => "QQ",
  277. ],
  278. "dateOfBirth" => "hah",
  279. "ssn" => "12345",
  280. ],
  281. "business" => [
  282. "legalName" => "``{}",
  283. "dbaName" => "{}``",
  284. "taxId" => "bad",
  285. "address" => [
  286. "streetAddress" => "nope",
  287. "postalCode" => "1",
  288. "region" => "QQ",
  289. ],
  290. ],
  291. "funding" => [
  292. "destination" => "MY WALLET",
  293. "routingNumber" => "LEATHER",
  294. "accountNumber" => "BACK POCKET",
  295. "email" => "BILLFOLD",
  296. "mobilePhone" => "TRIFOLD"
  297. ],
  298. ];
  299. $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
  300. $this->assertEquals(false, $result->success);
  301. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("firstName");
  302. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_FIRST_NAME_IS_INVALID);
  303. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("lastName");
  304. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_LAST_NAME_IS_INVALID);
  305. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("email");
  306. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_EMAIL_IS_INVALID);
  307. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("phone");
  308. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_PHONE_IS_INVALID);
  309. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("streetAddress");
  310. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_STREET_ADDRESS_IS_INVALID);
  311. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("postalCode");
  312. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_POSTAL_CODE_IS_INVALID);
  313. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("region");
  314. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_REGION_IS_INVALID);
  315. $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("ssn");
  316. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_SSN_IS_INVALID);
  317. ;
  318. $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("legalName");
  319. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_LEGAL_NAME_IS_INVALID);
  320. $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("dbaName");
  321. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_DBA_NAME_IS_INVALID);
  322. $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("taxId");
  323. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_TAX_ID_IS_INVALID);
  324. $error = $result->errors->forKey("merchantAccount")->forKey("business")->forKey("address")->onAttribute("streetAddress");
  325. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_ADDRESS_STREET_ADDRESS_IS_INVALID);
  326. $error = $result->errors->forKey("merchantAccount")->forKey("business")->forKey("address")->onAttribute("postalCode");
  327. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_ADDRESS_POSTAL_CODE_IS_INVALID);
  328. $error = $result->errors->forKey("merchantAccount")->forKey("business")->forKey("address")->onAttribute("region");
  329. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_ADDRESS_REGION_IS_INVALID);
  330. $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("destination");
  331. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_DESTINATION_IS_INVALID);
  332. $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("routingNumber");
  333. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_ROUTING_NUMBER_IS_INVALID);
  334. $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("accountNumber");
  335. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_ACCOUNT_NUMBER_IS_INVALID);
  336. $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("email");
  337. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_EMAIL_IS_INVALID);
  338. $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("mobilePhone");
  339. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_MOBILE_PHONE_IS_INVALID);
  340. }
  341. public function testUpdateWithInvalidBusinessFields()
  342. {
  343. $params = [
  344. "business" => [
  345. "legalName" => "",
  346. "taxId" => "111223333",
  347. ]
  348. ];
  349. $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
  350. $this->assertEquals(false, $result->success);
  351. $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("legalName");
  352. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_LEGAL_NAME_IS_REQUIRED_WITH_TAX_ID);
  353. $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("taxId");
  354. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_TAX_ID_MUST_BE_BLANK);
  355. $params = [
  356. "business" => [
  357. "legalName" => "legal name",
  358. "taxId" => "",
  359. ]
  360. ];
  361. $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
  362. $this->assertEquals(false, $result->success);
  363. $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("taxId");
  364. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_TAX_ID_IS_REQUIRED_WITH_LEGAL_NAME);
  365. }
  366. public function testUpdateWithInvalidFundingFields()
  367. {
  368. $params = [
  369. "funding" => [
  370. "destination" => Braintree\MerchantAccount::FUNDING_DESTINATION_EMAIL,
  371. "email" => "",
  372. ]
  373. ];
  374. $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
  375. $this->assertEquals(false, $result->success);
  376. $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("email");
  377. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_EMAIL_IS_REQUIRED);
  378. $params = [
  379. "funding" => [
  380. "destination" => Braintree\MerchantAccount::FUNDING_DESTINATION_MOBILE_PHONE,
  381. "mobilePhone" => "",
  382. ]
  383. ];
  384. $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
  385. $this->assertEquals(false, $result->success);
  386. $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("mobilePhone");
  387. $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_MOBILE_PHONE_IS_REQUIRED);
  388. }
  389. public function testCreateForCurrency()
  390. {
  391. $gateway = new Braintree\Gateway([
  392. 'clientId' => 'client_id$development$signup_client_id',
  393. 'clientSecret' => 'client_secret$development$signup_client_secret',
  394. ]);
  395. $result = $gateway->merchant()->create([
  396. 'email' => 'name@email.com',
  397. 'countryCodeAlpha3' => 'GBR',
  398. 'paymentMethods' => ['credit_card', 'paypal'],
  399. ]);
  400. $this->assertEquals(true, $result->success);
  401. $gateway = new Braintree\Gateway([
  402. 'accessToken' => $result->credentials->accessToken,
  403. ]);
  404. $result = $gateway->merchantAccount()->createForCurrency([
  405. 'currency' => "USD",
  406. ]);
  407. $this->assertEquals(true, $result->success);
  408. $merchantAccount = $result->merchantAccount;
  409. $this->assertEquals("USD", $merchantAccount->currencyIsoCode);
  410. $this->assertEquals("USD", $merchantAccount->id);
  411. }
  412. public function testCreateForCurrencyWithDuplicateCurrency()
  413. {
  414. $gateway = new Braintree\Gateway([
  415. 'clientId' => 'client_id$development$signup_client_id',
  416. 'clientSecret' => 'client_secret$development$signup_client_secret',
  417. ]);
  418. $result = $gateway->merchant()->create([
  419. 'email' => 'name@email.com',
  420. 'countryCodeAlpha3' => 'GBR',
  421. 'paymentMethods' => ['credit_card', 'paypal'],
  422. ]);
  423. $this->assertEquals(true, $result->success);
  424. $gateway = new Braintree\Gateway([
  425. 'accessToken' => $result->credentials->accessToken,
  426. ]);
  427. $merchantAccount = $result->merchant->merchantAccounts[0];
  428. $result = $gateway->merchantAccount()->createForCurrency([
  429. 'currency' => "GBP",
  430. ]);
  431. $this->assertEquals(false, $result->success);
  432. $errors = $result->errors->forKey('merchant')->onAttribute('currency');
  433. $this->assertEquals(Braintree\Error\Codes::MERCHANT_MERCHANT_ACCOUNT_EXISTS_FOR_CURRENCY, $errors[0]->code);
  434. }
  435. public function testCreateForCurrencyWithInvalidCurrency()
  436. {
  437. $gateway = new Braintree\Gateway([
  438. 'clientId' => 'client_id$development$signup_client_id',
  439. 'clientSecret' => 'client_secret$development$signup_client_secret',
  440. ]);
  441. $result = $gateway->merchant()->create([
  442. 'email' => 'name@email.com',
  443. 'countryCodeAlpha3' => 'GBR',
  444. 'paymentMethods' => ['credit_card', 'paypal'],
  445. ]);
  446. $this->assertEquals(true, $result->success);
  447. $gateway = new Braintree\Gateway([
  448. 'accessToken' => $result->credentials->accessToken,
  449. ]);
  450. $result = $gateway->merchantAccount()->createForCurrency([
  451. 'currency' => "FAKE_CURRENCY",
  452. ]);
  453. $this->assertEquals(false, $result->success);
  454. $errors = $result->errors->forKey('merchant')->onAttribute('currency');
  455. $this->assertEquals(Braintree\Error\Codes::MERCHANT_CURRENCY_IS_INVALID, $errors[0]->code);
  456. }
  457. public function testCreateForCurrencyWithoutCurrency()
  458. {
  459. $gateway = new Braintree\Gateway([
  460. 'clientId' => 'client_id$development$signup_client_id',
  461. 'clientSecret' => 'client_secret$development$signup_client_secret',
  462. ]);
  463. $result = $gateway->merchant()->create([
  464. 'email' => 'name@email.com',
  465. 'countryCodeAlpha3' => 'GBR',
  466. 'paymentMethods' => ['credit_card', 'paypal'],
  467. ]);
  468. $this->assertEquals(true, $result->success);
  469. $gateway = new Braintree\Gateway([
  470. 'accessToken' => $result->credentials->accessToken,
  471. ]);
  472. $result = $gateway->merchantAccount()->createForCurrency([]);
  473. $this->assertEquals(false, $result->success);
  474. $errors = $result->errors->forKey('merchant')->onAttribute('currency');
  475. $this->assertEquals(Braintree\Error\Codes::MERCHANT_CURRENCY_IS_REQUIRED, $errors[0]->code);
  476. }
  477. public function testCreateForCurrencyWithDuplicateId()
  478. {
  479. $gateway = new Braintree\Gateway([
  480. 'clientId' => 'client_id$development$signup_client_id',
  481. 'clientSecret' => 'client_secret$development$signup_client_secret',
  482. ]);
  483. $result = $gateway->merchant()->create([
  484. 'email' => 'name@email.com',
  485. 'countryCodeAlpha3' => 'GBR',
  486. 'paymentMethods' => ['credit_card', 'paypal'],
  487. ]);
  488. $this->assertEquals(true, $result->success);
  489. $gateway = new Braintree\Gateway([
  490. 'accessToken' => $result->credentials->accessToken,
  491. ]);
  492. $merchantAccount = $result->merchant->merchantAccounts[0];
  493. $result = $gateway->merchantAccount()->createForCurrency([
  494. 'currency' => "USD",
  495. 'id' => $merchantAccount->id,
  496. ]);
  497. $this->assertEquals(false, $result->success);
  498. $errors = $result->errors->forKey('merchant')->onAttribute('id');
  499. $this->assertEquals(Braintree\Error\Codes::MERCHANT_MERCHANT_ACCOUNT_EXISTS_FOR_ID, $errors[0]->code);
  500. }
  501. public function testAllReturnsAllMerchantAccounts()
  502. {
  503. $gateway = new Braintree\Gateway([
  504. 'clientId' => 'client_id$development$integration_client_id',
  505. 'clientSecret' => 'client_secret$development$integration_client_secret',
  506. ]);
  507. $code = Test\Braintree\OAuthTestHelper::createGrant($gateway, [
  508. 'merchant_public_id' => 'integration_merchant_id',
  509. 'scope' => 'read_write'
  510. ]);
  511. $credentials = $gateway->oauth()->createTokenFromCode([
  512. 'code' => $code,
  513. ]);
  514. $gateway = new Braintree\Gateway([
  515. 'accessToken' => $credentials->accessToken
  516. ]);
  517. $result = $gateway->merchantAccount()->all();
  518. $merchantAccounts = [];
  519. foreach($result as $ma) {
  520. array_push($merchantAccounts, $ma);
  521. }
  522. $this->assertEquals(true, count($merchantAccounts) > 20);
  523. }
  524. public function testAllReturnsMerchantAccountWithCorrectAttributes()
  525. {
  526. $gateway = new Braintree\Gateway([
  527. 'clientId' => 'client_id$development$integration_client_id',
  528. 'clientSecret' => 'client_secret$development$integration_client_secret',
  529. ]);
  530. $result = $gateway->merchant()->create([
  531. 'email' => 'name@email.com',
  532. 'countryCodeAlpha3' => 'USA',
  533. 'paymentMethods' => ['credit_card', 'paypal'],
  534. ]);
  535. $gateway = new Braintree\Gateway([
  536. 'accessToken' => $result->credentials->accessToken,
  537. ]);
  538. $result = $gateway->merchantAccount()->all();
  539. $merchantAccounts = [];
  540. foreach($result as $ma) {
  541. array_push($merchantAccounts, $ma);
  542. }
  543. $this->assertEquals(1, count($merchantAccounts));
  544. $merchantAccount = $merchantAccounts[0];
  545. $this->assertEquals("USD", $merchantAccount->currencyIsoCode);
  546. $this->assertEquals(Braintree\MerchantAccount::STATUS_ACTIVE, $merchantAccount->status);
  547. $this->assertTrue($merchantAccount->default);
  548. }
  549. }