MasterpassCardTest.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 MasterpassCardTest extends Setup
  9. {
  10. public function testCreateWithMasterpassCardNonce()
  11. {
  12. $customer = Braintree\Customer::createNoValidate();
  13. $result = Braintree\PaymentMethod::create([
  14. 'customerId' => $customer->id,
  15. 'paymentMethodNonce' => Braintree\Test\Nonces::$masterpassDiscover,
  16. ]);
  17. $this->assertTrue($result->success);
  18. $masterpassCard = $result->paymentMethod;
  19. $this->assertSame(Braintree\CreditCard::DISCOVER, $masterpassCard->cardType);
  20. $this->assertTrue($masterpassCard->default);
  21. $this->assertContains('discover', $masterpassCard->imageUrl);
  22. $this->assertTrue(intval($masterpassCard->expirationMonth) > 0);
  23. $this->assertTrue(intval($masterpassCard->expirationYear) > 0);
  24. $this->assertSame($customer->id, $masterpassCard->customerId);
  25. $this->assertSame($masterpassCard->last4, '1117');
  26. $this->assertSame($masterpassCard->maskedNumber, '601111******1117');
  27. $this->assertNotNull($masterpassCard->billingAddress);
  28. $this->assertNotNull($masterpassCard->bin);
  29. $this->assertNotNull($masterpassCard->cardType);
  30. $this->assertNotNull($masterpassCard->cardholderName);
  31. $this->assertNotNull($masterpassCard->commercial);
  32. $this->assertNotNull($masterpassCard->countryOfIssuance);
  33. $this->assertNotNull($masterpassCard->createdAt);
  34. $this->assertNotNull($masterpassCard->customerId);
  35. $this->assertNotNull($masterpassCard->customerLocation);
  36. $this->assertNotNull($masterpassCard->debit);
  37. $this->assertNotNull($masterpassCard->default);
  38. $this->assertNotNull($masterpassCard->durbinRegulated);
  39. $this->assertNotNull($masterpassCard->expirationDate);
  40. $this->assertNotNull($masterpassCard->expirationMonth);
  41. $this->assertNotNull($masterpassCard->expirationYear);
  42. $this->assertNotNull($masterpassCard->expired);
  43. $this->assertNotNull($masterpassCard->healthcare);
  44. $this->assertNotNull($masterpassCard->imageUrl);
  45. $this->assertNotNull($masterpassCard->issuingBank);
  46. $this->assertNotNull($masterpassCard->last4);
  47. $this->assertNotNull($masterpassCard->maskedNumber);
  48. $this->assertNotNull($masterpassCard->payroll);
  49. $this->assertNotNull($masterpassCard->prepaid);
  50. $this->assertNotNull($masterpassCard->productId);
  51. $this->assertNotNull($masterpassCard->subscriptions);
  52. $this->assertNotNull($masterpassCard->token);
  53. $this->assertNotNull($masterpassCard->uniqueNumberIdentifier);
  54. $this->assertNotNull($masterpassCard->updatedAt);
  55. }
  56. public function testTransactionSearchWithMasterpass()
  57. {
  58. $transaction = Braintree\Transaction::saleNoValidate([
  59. 'amount' => Braintree\Test\TransactionAmounts::$authorize,
  60. 'paymentMethodNonce' => Braintree\Test\Nonces::$masterpassDiscover,
  61. ]);
  62. $collection = Braintree\Transaction::search([
  63. Braintree\TransactionSearch::id()->is($transaction->id),
  64. Braintree\TransactionSearch::paymentInstrumentType()->is(Braintree\PaymentInstrumentType::MASTERPASS_CARD)
  65. ]);
  66. $this->assertEquals($transaction->paymentInstrumentType, Braintree\PaymentInstrumentType::MASTERPASS_CARD);
  67. $this->assertEquals($transaction->id, $collection->firstItem()->id);
  68. }
  69. public function testCreateCustomerwithMasterpassCard()
  70. {
  71. $nonce = Braintree\Test\Nonces::$masterpassDiscover;
  72. $result = Braintree\Customer::create([
  73. 'paymentMethodNonce' => $nonce
  74. ]);
  75. $this->assertTrue($result->success);
  76. $customer = $result->customer;
  77. $this->assertNotNull($customer->masterpassCards[0]);
  78. $this->assertNotNull($customer->paymentMethods[0]);
  79. }
  80. public function testCreateTransactionWithMasterpassNonceAndVault()
  81. {
  82. $result = Braintree\Transaction::sale([
  83. 'amount' => '47.00',
  84. 'paymentMethodNonce' => Braintree\Test\Nonces::$masterpassAmEx,
  85. 'options' => [
  86. 'storeInVault' => true
  87. ]
  88. ]);
  89. $this->assertTrue($result->success);
  90. $transaction = $result->transaction;
  91. $this->assertEquals('47.00', $transaction->amount);
  92. $masterpassCardDetails = $transaction->masterpassCardDetails;
  93. $this->assertSame(Braintree\CreditCard::AMEX, $masterpassCardDetails->cardType);
  94. $this->assertNotNull($masterpassCardDetails->bin);
  95. $this->assertNotNull($masterpassCardDetails->cardType);
  96. $this->assertNotNull($masterpassCardDetails->cardholderName);
  97. $this->assertNotNull($masterpassCardDetails->commercial);
  98. $this->assertNotNull($masterpassCardDetails->countryOfIssuance);
  99. $this->assertNotNull($masterpassCardDetails->customerLocation);
  100. $this->assertNotNull($masterpassCardDetails->debit);
  101. $this->assertNotNull($masterpassCardDetails->durbinRegulated);
  102. $this->assertNotNull($masterpassCardDetails->expirationDate);
  103. $this->assertNotNull($masterpassCardDetails->expirationMonth);
  104. $this->assertNotNull($masterpassCardDetails->expirationYear);
  105. $this->assertNotNull($masterpassCardDetails->healthcare);
  106. $this->assertNotNull($masterpassCardDetails->imageUrl);
  107. $this->assertNotNull($masterpassCardDetails->issuingBank);
  108. $this->assertNotNull($masterpassCardDetails->last4);
  109. $this->assertNotNull($masterpassCardDetails->maskedNumber);
  110. $this->assertNotNull($masterpassCardDetails->payroll);
  111. $this->assertNotNull($masterpassCardDetails->prepaid);
  112. $this->assertNotNull($masterpassCardDetails->productId);
  113. $this->assertNotNull($masterpassCardDetails->token);
  114. }
  115. }