PHP Classes

File: billing.php

Recommend this page to a friend!
  Classes of Faris AL-Otabi   Netflix Clone   billing.php   Download  
File: billing.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Netflix Clone
Manage a library of movies to rent like Netflix
Author: By
Last change:
Date: 2 months ago
Size: 1,056 bytes
 

Contents

Class file image Download
<?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 Reeceflix')
  ->
setDescription('£9.99 setup fee and then recurring payments of £9.99 to Reeceflix')
  ->
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);
  }
?>