PaymentController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use PayPal\Auth\OAuthTokenCredential;
  5. use PayPal\Rest\ApiContext;
  6. use Response;
  7. use Redirect;
  8. use Captcha;
  9. use Cache;
  10. use PayPal\Api;
  11. use Paypal\Rest;
  12. use Paypal\Auth;
  13. class PaymentController extends Controller
  14. {
  15. function __construct()
  16. {
  17. //
  18. }
  19. public function create(Request $request)
  20. {
  21. $apiContext = new ApiContext(
  22. new OAuthTokenCredential(
  23. 'AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS', // ClientID
  24. 'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL' // ClientSecret
  25. )
  26. );
  27. $payer = new Api\Payer();
  28. $payer->setPaymentMethod('paypal');
  29. $amount = new \PayPal\Api\Amount();
  30. $amount->setTotal('1.00');
  31. $amount->setCurrency('USD');
  32. $transaction = new \PayPal\Api\Transaction();
  33. $transaction->setAmount($amount);
  34. $redirectUrls = new \PayPal\Api\RedirectUrls();
  35. $redirectUrls->setReturnUrl("https://example.com/your_redirect_url.html")
  36. ->setCancelUrl("https://example.com/your_cancel_url.html");
  37. $payment = new \PayPal\Api\Payment();
  38. $payment->setIntent('sale')
  39. ->setPayer($payer)
  40. ->setTransactions(array($transaction))
  41. ->setRedirectUrls($redirectUrls);
  42. }
  43. }