Guest User

Untitled

a guest
Jul 17th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. <?php
  2. require("pagarme-php/Pagarme.php");
  3.  
  4. $api_key = "SUA_CHAVE_DE_API";
  5. Pagarme::setApiKey($api_key);
  6.  
  7. $plan_id = "246102";
  8. $plan = PagarMe_Plan::findById($plan_id); //encontra um plano
  9.  
  10. $subscriptionData = array(
  11. 'plan' => $plan,
  12. 'customer' => $_POST['customer']
  13. );
  14.  
  15. if(isset($_POST['card_hash'])) {
  16. $card = new PagarMe_Card(array(
  17. 'card_hash' => $_POST['card_hash']
  18. ));
  19. $card->create();
  20. $subscriptionData['payment_method'] = 'credit_card';
  21. $subscriptionData['card_id'] = $card->id;
  22. } else {
  23. $subscriptionData['payment_method'] = 'boleto';
  24. }
  25.  
  26. $subscription = new PagarMe_Subscription($subscriptionData);
  27.  
  28. $subscription->create();
  29.  
  30. echo "Subscription ID: " . $subscription->id;
  31. ?>
Add Comment
Please, Sign In to add comment