Test.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. require_once('TestAutoLoad.php');
  3. use Culqi\Culqi;
  4. /**
  5. * Test Create
  6. */
  7. class Test extends PHPUnit_Framework_TestCase {
  8. protected $API_KEY;
  9. protected $PUBLIC_API_KEY;
  10. protected function setUp() {
  11. $this->PUBLIC_API_KEY = getenv("PUBLIC_API_KEY");
  12. $this->API_KEY = getenv("API_KEY");
  13. $this->culqi_token = new Culqi(array("api_key" => $this->PUBLIC_API_KEY ));
  14. $this->culqi = new Culqi(array("api_key" => $this->API_KEY ));
  15. }
  16. public function testValidIins() {
  17. $iin = $this->culqi_token->Iins->get("411111");
  18. $this->assertEquals('iin', $iin->object);
  19. }
  20. /**
  21. * Creación de un token con los datos de una tarjeta de prueba
  22. */
  23. protected function createToken() {
  24. $token = $this->culqi_token->Tokens->create(
  25. array(
  26. "card_number" => "4111111111111111",
  27. "cvv" => "123",
  28. "email" => "wmuro".uniqid()."@me.com",
  29. "expiration_month" => 9,
  30. "expiration_year" => 2020,
  31. "fingerprint" => "q352454534"
  32. )
  33. );
  34. return $token;
  35. }
  36. /**
  37. * Verificar creación de Token
  38. */
  39. public function testVerifyToken() {
  40. $this->assertEquals('token', $this->createToken()->object);
  41. }
  42. public function testFindToken() {
  43. $token = $this->culqi->Tokens->get($this->createToken()->id);
  44. $this->assertEquals('token', $token->object);
  45. }
  46. public function createCharge() {
  47. $charge = $this->culqi->Charges->create(
  48. array(
  49. "amount" => 1000,
  50. "capture" => true,
  51. "currency_code" => "PEN",
  52. "description" => "Venta de prueba",
  53. "email" => "test@culqi.com",
  54. "installments" => 0,
  55. "source_id" => $this->createToken()->id
  56. )
  57. );
  58. return $charge;
  59. }
  60. public function testCreateCharge() {
  61. // Verificacion del campo object no tenga el valor 'error'
  62. $this->assertEquals('charge', $this->createCharge()->object);
  63. }
  64. public function testFindCharge() {
  65. $charge = $this->culqi->Charges->get($this->createCharge()->id);
  66. $this->assertEquals('charge', $charge->object);
  67. }
  68. public function createPlan() {
  69. $plan = $this->culqi->Plans->create(
  70. array(
  71. "amount" => 10000,
  72. "currency_code" => "PEN",
  73. "interval" => "dias",
  74. "interval_count" => 1,
  75. "limit" => 12,
  76. "name" => "plan-culqi".uniqid(),
  77. "trial_days" => 15
  78. )
  79. );
  80. return $plan;
  81. }
  82. public function testCreatePlan() {
  83. // Verificacion del campo object no tenga el valor 'error'
  84. $this->assertEquals('plan', $this->createPlan()->object);
  85. }
  86. public function testFindPlan() {
  87. $plan = $this->culqi->Plans->get($this->createPlan()->id);
  88. $this->assertEquals('plan', $plan->object);
  89. }
  90. public function createCustomer() {
  91. $customer = $this->culqi->Customers->create(
  92. array(
  93. "address" => "av lima 123",
  94. "address_city" => "lima",
  95. "country_code" => "PE",
  96. "email" => "www@".uniqid()."me.com",
  97. "first_name" => "Will",
  98. "last_name" => "Muro",
  99. "metadata" => array("test"=>"test"),
  100. "phone_number" => 899898999
  101. )
  102. );
  103. return $customer;
  104. }
  105. public function testCreateCustomer() {
  106. $this->assertEquals('customer', $this->createCustomer()->object);
  107. }
  108. public function testFindCustomer() {
  109. $customer = $this->culqi->Customers->get($this->createCustomer()->id);
  110. $this->assertEquals('customer', $customer->object);
  111. }
  112. public function createCard() {
  113. $card = $this->culqi->Cards->create(
  114. array(
  115. "customer_id" => $this->createCustomer()->id,
  116. "token_id" => $this->createToken()->id
  117. )
  118. );
  119. return $card;
  120. }
  121. public function testCreateCard() {
  122. $this->assertEquals('card', $this->createCard()->object);
  123. }
  124. public function testFindCard() {
  125. $card = $this->culqi->Cards->get($this->createCard()->id);
  126. $this->assertEquals('card', $card->object);
  127. }
  128. public function createSubscription() {
  129. $subscription = $this->culqi->Subscriptions->create(
  130. array(
  131. "card_id" => $this->createCard()->id,
  132. "plan_id" => $this->createPlan()->id
  133. )
  134. );
  135. return $subscription;
  136. }
  137. public function testCreateSubscription() {
  138. $this->assertEquals('subscription',$this->createSubscription()->object);
  139. }
  140. public function testFindSubscription() {
  141. $subscription = $this->culqi->Subscriptions->get($this->createSubscription()->id);
  142. $this->assertEquals('subscription', $subscription->object);
  143. }
  144. public function createRefund() {
  145. $refund = $this->culqi->Refunds->create(
  146. array(
  147. "amount" => 500,
  148. "charge_id" => $this->createCharge()->id,
  149. "reason" => "solicitud_comprador"
  150. )
  151. );
  152. return $refund;
  153. }
  154. public function testCreateRefund() {
  155. $this->assertEquals('refund',$this->createRefund()->object);
  156. }
  157. public function testFindRefund() {
  158. $refund = $this->culqi->Refunds->get($this->createRefund()->id);
  159. $this->assertEquals('refund',$refund->object);
  160. }
  161. }