-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpaypal_execute.php
43 lines (36 loc) · 954 Bytes
/
paypal_execute.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* Created by PhpStorm.
* User: Ricardo
* Date: 24/03/2018
* Time: 18:58
*/
require_once "paypal_config.php";
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\ExecutePayment;
use PayPal\Api\Payment;
use PayPal\Api\PaymentExecution;
use PayPal\Api\Transaction;
// Get payment object by passing paymentId
if(isset($_REQUEST['paymentID'])){
$paymentId = $_REQUEST['paymentID'];
}
$payment = Payment::get($paymentId, $apiContext);
if(isset($_REQUEST['payerID'])){
$payerId = $_REQUEST['payerID'];
}
// Execute payment with payer id
$execution = new PaymentExecution();
$execution->setPayerId($payerId);
try {
// Execute payment
$result = $payment->execute($execution, $apiContext);
echo $result;
} catch (PayPal\Exception\PayPalConnectionException $ex) {
echo $ex->getCode();
echo $ex->getData();
die($ex);
} catch (Exception $ex) {
die($ex);
}