VisaCheckoutCardTest.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace Test\Integration;
  3. require_once dirname(__DIR__) . '/Setup.php';
  4. use Test;
  5. use Test\Braintree\CreditCardNumbers\CardTypeIndicators;
  6. use Test\Setup;
  7. use Braintree;
  8. class VisaCheckoutCardTest extends Setup
  9. {
  10. public function testCreateWithVisaCheckoutCardNonce()
  11. {
  12. $customer = Braintree\Customer::createNoValidate();
  13. $result = Braintree\PaymentMethod::create([
  14. 'customerId' => $customer->id,
  15. 'paymentMethodNonce' => Braintree\Test\Nonces::$visaCheckoutDiscover,
  16. ]);
  17. $this->assertTrue($result->success);
  18. $visaCheckoutCard = $result->paymentMethod;
  19. $this->assertNotNull($visaCheckoutCard->token);
  20. $this->assertSame(Braintree\CreditCard::DISCOVER, $visaCheckoutCard->cardType);
  21. $this->assertTrue($visaCheckoutCard->default);
  22. $this->assertContains('discover', $visaCheckoutCard->imageUrl);
  23. $this->assertTrue(intval($visaCheckoutCard->expirationMonth) > 0);
  24. $this->assertTrue(intval($visaCheckoutCard->expirationYear) > 0);
  25. $this->assertSame($customer->id, $visaCheckoutCard->customerId);
  26. $this->assertSame('abc123', $visaCheckoutCard->callId);
  27. $this->assertSame($visaCheckoutCard->last4, '1117');
  28. $this->assertSame($visaCheckoutCard->maskedNumber, '601111******1117');
  29. $this->assertNotNull($visaCheckoutCard->billingAddress);
  30. $this->assertNotNull($visaCheckoutCard->bin);
  31. $this->assertNotNull($visaCheckoutCard->callId);
  32. $this->assertNotNull($visaCheckoutCard->cardType);
  33. $this->assertNotNull($visaCheckoutCard->cardholderName);
  34. $this->assertNotNull($visaCheckoutCard->commercial);
  35. $this->assertNotNull($visaCheckoutCard->countryOfIssuance);
  36. $this->assertNotNull($visaCheckoutCard->createdAt);
  37. $this->assertNotNull($visaCheckoutCard->customerId);
  38. $this->assertNotNull($visaCheckoutCard->customerLocation);
  39. $this->assertNotNull($visaCheckoutCard->debit);
  40. $this->assertNotNull($visaCheckoutCard->default);
  41. $this->assertNotNull($visaCheckoutCard->durbinRegulated);
  42. $this->assertNotNull($visaCheckoutCard->expirationDate);
  43. $this->assertNotNull($visaCheckoutCard->expirationMonth);
  44. $this->assertNotNull($visaCheckoutCard->expirationYear);
  45. $this->assertNotNull($visaCheckoutCard->expired);
  46. $this->assertNotNull($visaCheckoutCard->healthcare);
  47. $this->assertNotNull($visaCheckoutCard->imageUrl);
  48. $this->assertNotNull($visaCheckoutCard->issuingBank);
  49. $this->assertNotNull($visaCheckoutCard->last4);
  50. $this->assertNotNull($visaCheckoutCard->maskedNumber);
  51. $this->assertNotNull($visaCheckoutCard->payroll);
  52. $this->assertNotNull($visaCheckoutCard->prepaid);
  53. $this->assertNotNull($visaCheckoutCard->productId);
  54. $this->assertNotNull($visaCheckoutCard->subscriptions);
  55. $this->assertNotNull($visaCheckoutCard->token);
  56. $this->assertNotNull($visaCheckoutCard->uniqueNumberIdentifier);
  57. $this->assertNotNull($visaCheckoutCard->updatedAt);
  58. }
  59. public function testCreateWithVisaCheckoutCardNonceWithVerification()
  60. {
  61. $customer = Braintree\Customer::createNoValidate();
  62. $result = Braintree\PaymentMethod::create([
  63. 'customerId' => $customer->id,
  64. 'paymentMethodNonce' => Braintree\Test\Nonces::$visaCheckoutDiscover,
  65. 'options' => [
  66. 'verifyCard' => true
  67. ]
  68. ]);
  69. $this->assertTrue($result->success);
  70. $visaCheckoutCard = $result->paymentMethod;
  71. $verification = $visaCheckoutCard->verification;
  72. $this->assertNotNull($verification);
  73. $this->assertNotNull($verification->status);
  74. }
  75. public function testTransactionSearchWithVisaCheckout()
  76. {
  77. $transaction = Braintree\Transaction::saleNoValidate([
  78. 'amount' => Braintree\Test\TransactionAmounts::$authorize,
  79. 'paymentMethodNonce' => Braintree\Test\Nonces::$visaCheckoutDiscover,
  80. ]);
  81. $collection = Braintree\Transaction::search([
  82. Braintree\TransactionSearch::id()->is($transaction->id),
  83. Braintree\TransactionSearch::paymentInstrumentType()->is(Braintree\PaymentInstrumentType::VISA_CHECKOUT_CARD)
  84. ]);
  85. $this->assertEquals($transaction->paymentInstrumentType, Braintree\PaymentInstrumentType::VISA_CHECKOUT_CARD);
  86. $this->assertEquals($transaction->id, $collection->firstItem()->id);
  87. }
  88. public function testCreateCustomerWithVisaCheckoutCard()
  89. {
  90. $nonce = Braintree\Test\Nonces::$visaCheckoutDiscover;
  91. $result = Braintree\Customer::create([
  92. 'paymentMethodNonce' => $nonce
  93. ]);
  94. $this->assertTrue($result->success);
  95. $customer = $result->customer;
  96. $this->assertNotNull($customer->visaCheckoutCards[0]);
  97. $this->assertNotNull($customer->paymentMethods[0]);
  98. }
  99. public function testCreateTransactionWithVisaCheckoutNonceAndVault()
  100. {
  101. $result = Braintree\Transaction::sale([
  102. 'amount' => '47.00',
  103. 'paymentMethodNonce' => Braintree\Test\Nonces::$visaCheckoutAmEx,
  104. 'options' => [
  105. 'storeInVault' => true
  106. ]
  107. ]);
  108. $this->assertTrue($result->success);
  109. $transaction = $result->transaction;
  110. $this->assertEquals('47.00', $transaction->amount);
  111. $visaCheckoutCardDetails = $transaction->visaCheckoutCardDetails;
  112. $this->assertSame(Braintree\CreditCard::AMEX, $visaCheckoutCardDetails->cardType);
  113. $this->assertNotNull($visaCheckoutCardDetails->bin);
  114. $this->assertNotNull($visaCheckoutCardDetails->callId);
  115. $this->assertNotNull($visaCheckoutCardDetails->cardType);
  116. $this->assertNotNull($visaCheckoutCardDetails->cardholderName);
  117. $this->assertNotNull($visaCheckoutCardDetails->commercial);
  118. $this->assertNotNull($visaCheckoutCardDetails->countryOfIssuance);
  119. $this->assertNotNull($visaCheckoutCardDetails->customerLocation);
  120. $this->assertNotNull($visaCheckoutCardDetails->debit);
  121. $this->assertNotNull($visaCheckoutCardDetails->durbinRegulated);
  122. $this->assertNotNull($visaCheckoutCardDetails->expirationDate);
  123. $this->assertNotNull($visaCheckoutCardDetails->expirationMonth);
  124. $this->assertNotNull($visaCheckoutCardDetails->expirationYear);
  125. $this->assertNotNull($visaCheckoutCardDetails->healthcare);
  126. $this->assertNotNull($visaCheckoutCardDetails->imageUrl);
  127. $this->assertNotNull($visaCheckoutCardDetails->issuingBank);
  128. $this->assertNotNull($visaCheckoutCardDetails->last4);
  129. $this->assertNotNull($visaCheckoutCardDetails->maskedNumber);
  130. $this->assertNotNull($visaCheckoutCardDetails->payroll);
  131. $this->assertNotNull($visaCheckoutCardDetails->prepaid);
  132. $this->assertNotNull($visaCheckoutCardDetails->productId);
  133. $this->assertNotNull($visaCheckoutCardDetails->token);
  134. }
  135. }