IdealPaymentTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 IdealPaymentTest extends Setup
  8. {
  9. public function testFindIdealPayment()
  10. {
  11. $http = new HttpClientApi(Braintree\Configuration::$global);
  12. $idealPaymentId = Test\Helper::generateValidIdealPaymentId();
  13. $foundIdealPayment= Braintree\IdealPayment::find($idealPaymentId);
  14. $this->assertInstanceOf('Braintree\IdealPayment', $foundIdealPayment);
  15. $this->assertRegExp('/^idealpayment_\w{6,}$/', $foundIdealPayment->id);
  16. $this->assertRegExp('/^\d{16,}$/', $foundIdealPayment->idealTransactionId);
  17. $this->assertNotNull($foundIdealPayment->currency);
  18. $this->assertNotNull($foundIdealPayment->amount);
  19. $this->assertEquals('COMPLETE', $foundIdealPayment->status);
  20. $this->assertEquals('ABC123', $foundIdealPayment->orderId);
  21. $this->assertNotNull($foundIdealPayment->issuer);
  22. $this->assertRegExp('/^https:\/\//', $foundIdealPayment->approvalUrl);
  23. $this->assertNotNull($foundIdealPayment->ibanBankAccount->maskedIban);
  24. $this->assertNotNull($foundIdealPayment->ibanBankAccount->bic);
  25. $this->assertNotNull($foundIdealPayment->ibanBankAccount->ibanCountry);
  26. $this->assertNotNull($foundIdealPayment->ibanBankAccount->description);
  27. $this->assertRegExp('/^\d{4}$/', $foundIdealPayment->ibanBankAccount->ibanAccountNumberLast4);
  28. }
  29. public function testFindIdealPayment_throwsIfCannotBeFound()
  30. {
  31. $this->setExpectedException('Braintree\Exception\NotFound');
  32. Braintree\IdealPayment::find(Test\Helper::generateInvalidIdealPaymentId());
  33. }
  34. public function testSale_createsASaleUsingId()
  35. {
  36. $http = new HttpClientApi(Braintree\Configuration::$global);
  37. $idealPaymentId = Test\Helper::generateValidIdealPaymentId();
  38. $result = Braintree\IdealPayment::sale($idealPaymentId, [
  39. 'merchantAccountId' => 'ideal_merchant_account',
  40. 'amount' => '100.00',
  41. 'orderId' => 'ABC123'
  42. ]);
  43. $this->assertTrue($result->success);
  44. $transaction = $result->transaction;
  45. $this->assertEquals(Braintree\Transaction::SETTLED, $transaction->status);
  46. $this->assertEquals(Braintree\Transaction::SALE, $transaction->type);
  47. $this->assertEquals('100.00', $transaction->amount);
  48. $this->assertRegExp('/^idealpayment_\w{6,}$/', $transaction->idealPayment->idealPaymentId);
  49. $this->assertRegExp('/^\d{16,}$/', $transaction->idealPayment->idealTransactionId);
  50. $this->assertRegExp('/^https:\/\//', $transaction->idealPayment->imageUrl);
  51. $this->assertNotNull($transaction->idealPayment->maskedIban);
  52. $this->assertNotNull($transaction->idealPayment->bic);
  53. }
  54. public function testSale_createsASaleWithNotCompletePayment()
  55. {
  56. $http = new HttpClientApi(Braintree\Configuration::$global);
  57. $idealPaymentId = Test\Helper::generateValidIdealPaymentId('3.00');
  58. $result = Braintree\IdealPayment::sale($idealPaymentId, [
  59. 'merchantAccountId' => 'ideal_merchant_account',
  60. 'amount' => '3.00',
  61. 'orderId' => 'ABC123'
  62. ]);
  63. $this->assertFalse($result->success);
  64. $baseErrors = $result->errors->forKey('transaction')->onAttribute('paymentMethodNonce');
  65. $this->assertEquals(Braintree\Error\Codes::TRANSACTION_IDEAL_PAYMENT_NOT_COMPLETE, $baseErrors[0]->code);
  66. }
  67. public function testSale_createsASaleUsingInvalidId()
  68. {
  69. $http = new HttpClientApi(Braintree\Configuration::$global);
  70. $result = Braintree\IdealPayment::sale('invalid_id', [
  71. 'merchantAccountId' => 'ideal_merchant_account',
  72. 'amount' => '100.00',
  73. 'orderId' => 'ABC123'
  74. ]);
  75. $this->assertFalse($result->success);
  76. $baseErrors = $result->errors->forKey('transaction')->onAttribute('paymentMethodNonce');
  77. $this->assertEquals(Braintree\Error\Codes::TRANSACTION_PAYMENT_METHOD_NONCE_UNKNOWN, $baseErrors[0]->code);
  78. }
  79. }