PageRenderTime 47ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/res/example/index.php

https://gitlab.com/issei-m/spike-php
PHP | 59 lines | 37 code | 17 blank | 5 comment | 0 complexity | 7a7e76fd0acd220c026232c28a2572ff MD5 | raw file
  1. <?php
  2. require __DIR__ . '/../../vendor/autoload.php';
  3. require __DIR__ . '/definition.php';
  4. $spike = new \Issei\Spike\Spike(API_SECRET);
  5. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  6. echo '<h1>Retrieve the token</h1>';
  7. $req = new \Issei\Spike\TokenRequest();
  8. $req
  9. ->setCardNumber('4444333322221111')
  10. ->setExpirationMonth(12)
  11. ->setExpirationYear(19)
  12. ->setHolderName('Taro Spike')
  13. ->setSecurityCode('123')
  14. ->setCurrency('JPY')
  15. ->setEmail('test@example.jp')
  16. ;
  17. dump($token = $spike->requestToken($req));
  18. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  19. echo '<h1>New charge</h1>';
  20. $req = new \Issei\Spike\ChargeRequest();
  21. $req
  22. ->setAmount(100, 'JPY')
  23. ->setToken($token)
  24. ->addProduct(
  25. (new \Issei\Spike\Model\Product(uniqid('product-', true)))
  26. ->setTitle('Title')
  27. ->setDescription('Description')
  28. ->setCount(1)
  29. ->setPrice(100, 'USD')
  30. ->setLanguage('JA')
  31. )
  32. ;
  33. dump($spike->charge($req));
  34. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  35. echo '<h1>Retrieve charges</h1>';
  36. dump($charges = $spike->getCharges(5));
  37. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  38. echo '<h1>Retrieve a charge</h1>';
  39. dump($charge = $spike->getCharge($charges[0]));
  40. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41. echo '<h1>Refund the charge</h1>';
  42. dump($spike->refund($charge));