DeleteTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. require_once('TestAutoLoad.php');
  3. use Culqi\Culqi;
  4. class DeleteTest extends PHPUnit_Framework_TestCase
  5. {
  6. protected $API_KEY;
  7. protected $PUBLIC_API_KEY;
  8. protected function setUp() {
  9. $this->PUBLIC_API_KEY = getenv("PUBLIC_API_KEY");
  10. $this->API_KEY = getenv("API_KEY");
  11. $this->culqi_token = new Culqi(array("api_key" => $this->PUBLIC_API_KEY ));
  12. $this->culqi = new Culqi(array("api_key" => $this->API_KEY ));
  13. }
  14. protected function createToken() {
  15. $token = $this->culqi_token->Tokens->create(
  16. array(
  17. "card_number" => "4111111111111111",
  18. "cvv" => "123",
  19. "email" => "wmuro".uniqid()."@me.com",
  20. "expiration_month" => 9,
  21. "expiration_year" => 2020,
  22. "fingerprint" => "q352454534"
  23. )
  24. );
  25. return $token;
  26. }
  27. public function createCustomer() {
  28. $customer = $this->culqi->Customers->create(
  29. array(
  30. "address" => "av lima 123",
  31. "address_city" => "lima",
  32. "country_code" => "PE",
  33. "email" => "www@".uniqid()."me.com",
  34. "first_name" => "Will",
  35. "last_name" => "Muro",
  36. "metadata" => array("test"=>"test"),
  37. "phone_number" => 899898999
  38. )
  39. );
  40. return $customer;
  41. }
  42. public function createCard() {
  43. $card = $this->culqi->Cards->create(
  44. array(
  45. "customer_id" => $this->createCustomer()->id,
  46. "token_id" => $this->createToken()->id
  47. )
  48. );
  49. return $card;
  50. }
  51. public function createPlan() {
  52. $plan = $this->culqi->Plans->create(
  53. array(
  54. "amount" => 10000,
  55. "currency_code" => "PEN",
  56. "interval" => "dias",
  57. "interval_count" => 1,
  58. "limit" => 12,
  59. "name" => "plan-culqi".uniqid(),
  60. "trial_days" => 15
  61. )
  62. );
  63. return $plan;
  64. }
  65. public function createSubscription() {
  66. $subscription = $this->culqi->Subscriptions->create(
  67. array(
  68. "card_id" => $this->createCard()->id,
  69. "plan_id" => $this->createPlan()->id
  70. )
  71. );
  72. return $subscription;
  73. }
  74. public function testDeleteSubscription() {
  75. $subscriptionDeleted = $this->culqi->Subscriptions->delete($this->createSubscription()->id);
  76. $this->assertTrue($subscriptionDeleted->deleted);
  77. }
  78. public function testDeletePlan() {
  79. $planDeleted = $this->culqi->Plans->delete($this->createPlan()->id);
  80. $this->assertTrue($planDeleted->deleted);
  81. }
  82. public function testDeleteCard() {
  83. $cardDeleted = $this->culqi->Cards->delete($this->createCard()->id);
  84. $this->assertTrue($cardDeleted->deleted);
  85. }
  86. public function testDeleteCustomer() {
  87. $customerDeleted = $this->culqi->Customers->delete($this->createCustomer()->id);
  88. $this->assertTrue($customerDeleted->deleted);
  89. }
  90. }