-
Notifications
You must be signed in to change notification settings - Fork 0
/
billing.php
45 lines (35 loc) · 1.03 KB
/
billing.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
44
45
<?php
require_once("includes/paypalConfig.php");
require_once("billingPlan.php");
$id = $plan->getId();
use PayPal\Api\Agreement;
use PayPal\Api\Payer;
use PayPal\Api\Plan;
use PayPal\Api\ShippingAddress;
// Create new agreement
$agreement = new Agreement();
$agreement->setName('Subscription to Fulix')
->setDescription('€9,99 setup fee and then recurring payments of € 9,99 to Fulix')
->setStartDate(gmdate("Y-m-d\TH:i:s\Z", strtotime("+1 month", time())));
// Set plan id
$plan = new Plan();
$plan->setId($id);
$agreement->setPlan($plan);
// Add payer type
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$agreement->setPayer($payer);
try {
// Create agreement
$agreement = $agreement->create($apiContext);
// Extract approval URL to redirect user
$approvalUrl = $agreement->getApprovalLink();
header("Location: $approvalUrl");
} catch (PayPal\Exception\PayPalConnectionException $ex) {
echo $ex->getCode();
echo $ex->getData();
die($ex);
} catch (Exception $ex) {
die($ex);
}
?>