Created
December 23, 2018 20:52
-
-
Save joeyemery/47564309a0aa4a389d4fe55a99626ea5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\URL; | |
class PaymentController extends Controller { | |
public function __construct() | |
{ | |
$this->_paypalContext = new \PayPal\Rest\ApiContext( | |
new \PayPal\Auth\OAuthTokenCredential( | |
'AXwCbie6CfbK6OTYZl0UG-InBNVJa_xZnBJoUYytlE5FMYWtdIZHxMIROLWcwaig5vHMuNC-LMwfYotw', // ClientID | |
'EI-n0gh5gRRDa3tC7taTcRtJky18Z08NjHlgpvFdyxFmannSzu1EA6w8PxcbWoKjgm0XFRjN9W0Zji2L' // ClientSecret | |
) | |
); | |
} | |
public function payPaypal() | |
{ | |
$payer = new \PayPal\Api\Payer(); | |
$payer->setPaymentMethod('paypal'); | |
$amount = new \PayPal\Api\Amount(); | |
$amount->setTotal('1.00'); | |
$amount->setCurrency('USD'); | |
$transaction = new \PayPal\Api\Transaction(); | |
$transaction->setAmount($amount); | |
$redirectUrls = new \PayPal\Api\RedirectUrls(); | |
$redirectUrls->setReturnUrl(route('paypal_status')) | |
->setCancelUrl(route('paypal_status')); | |
$payment = new \PayPal\Api\Payment(); | |
$payment->setIntent('sale') | |
->setPayer($payer) | |
->setTransactions(array($transaction)) | |
->setRedirectUrls($redirectUrls); | |
try { | |
$payment->create($this->_paypalContext); | |
return ['redirect_url' => $payment->getApprovalLink()]; | |
} catch (\PayPal\Exception\PayPalConnectionException $ex) { | |
echo $ex->getData(); | |
} | |
} | |
public function statusPaypal(Request $request) | |
{ | |
$payment_id = $request->get('paymentId'); | |
try { | |
$payment = \PayPal\Api\Payment::get($payment_id, $this->_paypalContext); | |
print_r($payment); | |
} catch (Exception $ex) { | |
print_r($ex->getData()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\URL; | |
class PaymentController extends Controller { | |
public function payStripe() | |
{ | |
Stripe\Stripe::setApiKey("sk_test_4eC39HqLyjWDarjtT1zdp7dc"); | |
$token = $_POST['stripeToken']; | |
$charge = \Stripe\Charge::create([ | |
'amount' => 999, | |
'currency' => 'usd', | |
'description' => 'Example charge', | |
'source' => $token, | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment