UsBankAccountVerificationTest.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 UsBankAccountVerificationTest extends Setup
  8. {
  9. public function test_createWithSuccessfulResponse()
  10. {
  11. $customer = Braintree\Customer::createNoValidate();
  12. $result = Braintree\PaymentMethod::create([
  13. 'customerId' => $customer->id,
  14. 'paymentMethodNonce' => Test\Helper::generateValidUsBankAccountNonce(),
  15. 'options' => [
  16. 'verificationMerchantAccountId' => Test\Helper::usBankMerchantAccount(),
  17. 'usBankAccountVerificationMethod' => 'network_check',
  18. ]
  19. ]);
  20. $usBankAccount = $result->paymentMethod;
  21. $this->assertEquals(1, count($usBankAccount->verifications));
  22. $verification = $usBankAccount->verifications[0];
  23. $this->assertEquals('network_check', $verification->verificationMethod);
  24. }
  25. public function test_findVerification()
  26. {
  27. $customer = Braintree\Customer::createNoValidate();
  28. $result = Braintree\PaymentMethod::create([
  29. 'customerId' => $customer->id,
  30. 'paymentMethodNonce' => Test\Helper::generateValidUsBankAccountNonce(),
  31. 'options' => [
  32. 'verificationMerchantAccountId' => Test\Helper::usBankMerchantAccount(),
  33. 'verificationMerchantAccountId' => Test\Helper::usBankMerchantAccount(),
  34. 'usBankAccountVerificationMethod' => Braintree\Result\UsBankAccountVerification::NETWORK_CHECK,
  35. ]
  36. ]);
  37. $usBankAccount = $result->paymentMethod;
  38. $this->assertEquals(1, count($usBankAccount->verifications));
  39. $createdVerification = $usBankAccount->verifications[0];
  40. $foundVerification = Braintree\UsBankAccountVerification::find($createdVerification->id);
  41. $this->assertEquals($foundVerification, $createdVerification);
  42. }
  43. public function test_searchVerification()
  44. {
  45. $customer = Braintree\Customer::createNoValidate();
  46. $result = Braintree\PaymentMethod::create([
  47. 'customerId' => $customer->id,
  48. 'paymentMethodNonce' => Test\Helper::generateValidUsBankAccountNonce(),
  49. 'options' => [
  50. 'verificationMerchantAccountId' => Test\Helper::usBankMerchantAccount(),
  51. 'usBankAccountVerificationMethod' => Braintree\Result\UsBankAccountVerification::INDEPENDENT_CHECK,
  52. ]
  53. ]);
  54. $usBankAccount = $result->paymentMethod;
  55. $this->assertEquals(1, count($usBankAccount->verifications));
  56. $createdVerification = $usBankAccount->verifications[0];
  57. $query = [Braintree\UsBankAccountVerificationSearch::id()->is($createdVerification->id)];
  58. $query[] = Braintree\UsBankAccountVerificationSearch::accountNumber()->endsWith("1234");
  59. $collection = Braintree\UsBankAccountVerification::search($query);
  60. $this->assertEquals(1, $collection->maximumCount());
  61. }
  62. public function test_attemptConfirmMicroTransferAmounts()
  63. {
  64. $gateway = new Braintree\Gateway([
  65. 'environment' => 'development',
  66. 'merchantId' => 'integration2_merchant_id',
  67. 'publicKey' => 'integration2_public_key',
  68. 'privateKey' => 'integration2_private_key'
  69. ]);
  70. $customer = $gateway->customer()->create([
  71. 'firstName' => 'Joe',
  72. 'lastName' => 'Brown'
  73. ])->customer;
  74. $result = $gateway->paymentMethod()->create([
  75. 'customerId' => $customer->id,
  76. 'paymentMethodNonce' => Test\Helper::generateValidUsBankAccountNonce(),
  77. 'options' => [
  78. 'verificationMerchantAccountId' => Test\Helper::anotherUsBankMerchantAccount(),
  79. 'usBankAccountVerificationMethod' => Braintree\Result\UsBankAccountVerification::MICRO_TRANSFERS,
  80. ]
  81. ]);
  82. $usBankAccount = $result->paymentMethod;
  83. $this->assertEquals(1, count($usBankAccount->verifications));
  84. $createdVerification = $usBankAccount->verifications[0];
  85. $result = $gateway->usBankAccountVerification()->confirmMicroTransferAmounts($createdVerification->id, [1, 1]);
  86. $this->assertFalse($result->success);
  87. $amountErrors = $result->errors->forKey('usBankAccountVerification')->onAttribute('base');
  88. $this->assertEquals(
  89. Braintree\Error\Codes::US_BANK_ACCOUNT_VERIFICATION_AMOUNTS_DO_NOT_MATCH,
  90. $amountErrors[0]->code
  91. );
  92. }
  93. public function test_confirmMicroTransferAmountsSettled()
  94. {
  95. $gateway = new Braintree\Gateway([
  96. 'environment' => 'development',
  97. 'merchantId' => 'integration2_merchant_id',
  98. 'publicKey' => 'integration2_public_key',
  99. 'privateKey' => 'integration2_private_key'
  100. ]);
  101. $customer = $gateway->customer()->create([
  102. 'firstName' => 'Joe',
  103. 'lastName' => 'Brown'
  104. ])->customer;
  105. $result = $gateway->paymentMethod()->create([
  106. 'customerId' => $customer->id,
  107. 'paymentMethodNonce' => Test\Helper::generateValidUsBankAccountNonce('1000000000'),
  108. 'options' => [
  109. 'verificationMerchantAccountId' => Test\Helper::anotherUsBankMerchantAccount(),
  110. 'usBankAccountVerificationMethod' => Braintree\Result\UsBankAccountVerification::MICRO_TRANSFERS,
  111. ]
  112. ]);
  113. $usBankAccount = $result->paymentMethod;
  114. $this->assertEquals(1, count($usBankAccount->verifications));
  115. $createdVerification = $usBankAccount->verifications[0];
  116. $result = $gateway->usBankAccountVerification()->confirmMicroTransferAmounts($createdVerification->id, [17, 29]);
  117. $this->assertTrue($result->success);
  118. $usBankAccountVerification = $result->usBankAccountVerification;
  119. $this->assertEquals($usBankAccountVerification->status, Braintree\Result\UsBankAccountVerification::VERIFIED);
  120. $usBankAccount = $gateway->usBankAccount()->find($usBankAccountVerification->usBankAccount->token);
  121. $this->assertTrue($usBankAccount->verified);
  122. }
  123. public function test_confirmMicroTransferAmountsUnsettled()
  124. {
  125. $gateway = new Braintree\Gateway([
  126. 'environment' => 'development',
  127. 'merchantId' => 'integration2_merchant_id',
  128. 'publicKey' => 'integration2_public_key',
  129. 'privateKey' => 'integration2_private_key'
  130. ]);
  131. $customer = $gateway->customer()->create([
  132. 'firstName' => 'Joe',
  133. 'lastName' => 'Brown'
  134. ])->customer;
  135. $result = $gateway->paymentMethod()->create([
  136. 'customerId' => $customer->id,
  137. 'paymentMethodNonce' => Test\Helper::generateValidUsBankAccountNonce('1000000001'),
  138. 'options' => [
  139. 'verificationMerchantAccountId' => Test\Helper::anotherUsBankMerchantAccount(),
  140. 'usBankAccountVerificationMethod' => Braintree\Result\UsBankAccountVerification::MICRO_TRANSFERS,
  141. ]
  142. ]);
  143. $usBankAccount = $result->paymentMethod;
  144. $this->assertEquals(1, count($usBankAccount->verifications));
  145. $createdVerification = $usBankAccount->verifications[0];
  146. $result = $gateway->usBankAccountVerification()->confirmMicroTransferAmounts($createdVerification->id, [17, 29]);
  147. $this->assertTrue($result->success);
  148. $usBankAccountVerification = $result->usBankAccountVerification;
  149. $this->assertEquals($usBankAccountVerification->status, Braintree\Result\UsBankAccountVerification::PENDING);
  150. $usBankAccount = $gateway->usBankAccount()->find($usBankAccountVerification->usBankAccount->token);
  151. $this->assertFalse($usBankAccount->verified);
  152. }
  153. public function test_exceedRetryThreshold()
  154. {
  155. $gateway = new Braintree\Gateway([
  156. 'environment' => 'development',
  157. 'merchantId' => 'integration2_merchant_id',
  158. 'publicKey' => 'integration2_public_key',
  159. 'privateKey' => 'integration2_private_key'
  160. ]);
  161. $customer = $gateway->customer()->create([
  162. 'firstName' => 'Joe',
  163. 'lastName' => 'Brown'
  164. ])->customer;
  165. $result = $gateway->paymentMethod()->create([
  166. 'customerId' => $customer->id,
  167. 'paymentMethodNonce' => Test\Helper::generateValidUsBankAccountNonce(),
  168. 'options' => [
  169. 'verificationMerchantAccountId' => Test\Helper::anotherUsBankMerchantAccount(),
  170. 'usBankAccountVerificationMethod' => Braintree\Result\UsBankAccountVerification::MICRO_TRANSFERS,
  171. ]
  172. ]);
  173. $usBankAccount = $result->paymentMethod;
  174. $this->assertEquals(1, count($usBankAccount->verifications));
  175. $createdVerification = $usBankAccount->verifications[0];
  176. for ($i = 0; $i < 4; $i++) {
  177. $result = $gateway->usBankAccountVerification()->confirmMicroTransferAmounts($createdVerification->id, [1, 1]);
  178. $this->assertFalse($result->success);
  179. $amountErrors = $result->errors->forKey('usBankAccountVerification')->onAttribute('base');
  180. $this->assertEquals(
  181. Braintree\Error\Codes::US_BANK_ACCOUNT_VERIFICATION_AMOUNTS_DO_NOT_MATCH,
  182. $amountErrors[0]->code
  183. );
  184. }
  185. $result = $gateway->usBankAccountVerification()->confirmMicroTransferAmounts($createdVerification->id, [1, 1]);
  186. $this->assertFalse($result->success);
  187. $amountErrors = $result->errors->forKey('usBankAccountVerification')->onAttribute('base');
  188. $this->assertEquals(
  189. Braintree\Error\Codes::US_BANK_ACCOUNT_VERIFICATION_TOO_MANY_CONFIRMATION_ATTEMPTS,
  190. $amountErrors[0]->code
  191. );
  192. }
  193. }