Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit e743683bf1640f7e1606253f423ffb4146119db8 0 parents
Brent Shepherd authored
39 check-profile.php
@@ -0,0 +1,39 @@
+<?php
+require_once( 'functions.php' );
+
+if( ! isset( $_GET['profile_id'] ) && ! isset( $_GET['transaction_id'] ) )
+ die('Check Profile Requires a profile_id or transaction_id specified in the URL ($_GET)');
+
+?>
+<html>
+<head>
+ <title>PayPal Recurring Payment Profile</title>
+ <link rel="stylesheet" type="text/css" href="style.css" />
+</head>
+<body>
+ <div class="container" style="width: 550px;">
+
+ <?php if( isset( $_GET['profile_id'] ) ) : ?>
+ <?php $paypal = create_example_subscription(); ?>
+
+ <h2>PayPal Subscription Details</h2>
+ <pre>
+$paypal->get_profile_details( $_GET['profile_id'] ) ) =
+<? print_r( $paypal->get_profile_details( $_GET['profile_id'] ) ); ?>
+ </pre>
+
+ <?php else : ?>
+ <?php $paypal = create_example_purchase(); ?>
+
+ <h2>PayPal Transaction Details</h2>
+ <pre>
+$paypal->get_transaction_details( $_GET['transaction_id'] ) ); =
+<? print_r( $paypal->get_transaction_details( $_GET['transaction_id'] ) ); ?>
+ </pre>
+
+ <?php endif; ?>
+
+ <p><a href="<?php echo get_script_uri(); ?>" target="_top">Return to Examples Overview &raquo;</a></p>
+ <div>
+</body>
+</html>
7 checkout.php
@@ -0,0 +1,7 @@
+<?php
+require_once( 'functions.php' );
+
+$paypal = create_example_subscription();
+
+header('Location: ' . $paypal->get_checkout_url() ); // get_checkout_url() also requests a token
+exit();
26 example-purchase.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Example: Simple Purchase
+ *
+ * This example shows the simplest method of accepting a payment with PayPal.
+ */
+
+require_once( 'functions.php' );
+
+$paypal = create_example_purchase();
+
+?>
+<html>
+<head>
+ <title>PayPal - Digital Goods for Express Checkout Example</title>
+ <link rel="stylesheet" type="text/css" href="style.css" />
+</head>
+<body>
+ <div class="container">
+ <h2>PayPal Simple Purchase Demo</h2>
+ <p><b>Description:</b> <?php echo $paypal->get_description(); ?></p>
+ <p><b>Purchase price:</b> <?php echo $paypal->get_purchase_price(); ?></p>
+ <?php $paypal->print_buy_button(); ?>
+ </div>
+</body>
+</html>
34 example-subscription-checkout.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * Example: Separate Checkout Page
+ *
+ * This example shows how to use a buy button linking to a separate checkout page on your site.
+ *
+ * This principle advantage of this method is to only request a checkout token from PayPal when
+ * a user has committed to buying (rather than every time the buy button is loaded). This method
+ * massively improves page load time compared to the Simple Payment example.
+ *
+ * The only difference between this example and the Simple Example is that the print_buy_button()
+ * function is passed a array containing the href parameter of the custom checkout page & 'get_token'
+ * flag is set to false.
+ */
+
+require_once( 'functions.php' );
+
+$paypal = create_example_subscription();
+
+?>
+<html>
+<head>
+ <title>PayPal - Digital Goods for Express Checkout Example</title>
+ <link rel="stylesheet" type="text/css" href="style.css" />
+</head>
+<body>
+ <div class="container">
+ <h2>PayPal Recurring Payments Demo</h2>
+ <p><b>Description:</b> <?php echo $paypal->get_description(); ?></p>
+ <p><b>Subscription details:</b> <?php echo $paypal->get_subscription_string(); ?></p>
+ <?php $paypal->print_buy_button( array( 'href' => 'checkout.php', 'get_token' => false ) ); ?>
+ </div>
+</body>
+</html>
26 example-subscription.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Example: Simple Payment
+ *
+ * This example shows the simplest method of accepting a payment.
+ */
+
+require_once( 'functions.php' );
+
+$paypal = create_example_subscription();
+
+?>
+<html>
+<head>
+ <title>PayPal - Digital Goods for Express Checkout Example</title>
+ <link rel="stylesheet" type="text/css" href="style.css" />
+</head>
+<body>
+ <div class="container">
+ <h2>PayPal Recurring Payments Demo</h2>
+ <p><b>Description:</b> <?php echo $paypal->get_description(); ?></p>
+ <p><b>Subscription details:</b> <?php echo $paypal->get_subscription_string(); ?></p>
+ <?php $paypal->print_buy_button(); ?>
+ </div>
+</body>
+</html>
101 functions.php
@@ -0,0 +1,101 @@
+<?php
+/**
+ * A global variable for storing our PayPal Digital Goods Object
+ */
+global $paypal;
+
+require_once( '../paypal-digital-goods.class.php' );
+require_once( '../paypal-subscription.class.php' );
+require_once( '../paypal-purchase.class.php' );
+
+
+/**
+ * Used to create a central function for getting credentials for both Subscription & Purchase objects
+ */
+function set_credentials() {
+
+ /*
+ PayPal_Digital_Goods_Configuration::username( 'your_api_username' );
+ PayPal_Digital_Goods_Configuration::password( 'your_api_password' );
+ PayPal_Digital_Goods_Configuration::signature( 'your_api_signature' );
+ */
+
+ PayPal_Digital_Goods_Configuration::username( 'digita_1308916325_biz_api1.gmail.com' );
+ PayPal_Digital_Goods_Configuration::password( '1308916362' );
+ PayPal_Digital_Goods_Configuration::signature( 'AFnwAcqRkyW0yPYgkjqTkIGqPbSfAyVFbnFAjXCRltVZFzlJyi2.HbxW' );
+
+ PayPal_Digital_Goods_Configuration::return_url( get_script_uri( 'return.php?paypal=paid' ) );
+ PayPal_Digital_Goods_Configuration::cancel_url( get_script_uri( 'return.php?paypal=cancel' ) );
+ PayPal_Digital_Goods_Configuration::business_name( 'Demo Store' );
+
+ if( PayPal_Digital_Goods_Configuration::username() == 'your_api_username' || PayPal_Digital_Goods_Configuration::password() == 'your_api_password' || PayPal_Digital_Goods_Configuration::signature() == 'your_api_signature' )
+ exit( 'You must set your API credentials in ' . __FILE__ . ' for this example to work.' );
+}
+
+/**
+ * Creates a PayPal Digital Goods Purchase Object
+ */
+function create_example_purchase() {
+
+ set_credentials();
+
+ $purchase_details = array(
+ 'name' => 'Digital Good Purchase Example',
+ 'description' => 'Example Digital Good Purchase',
+ 'amount' => '12.00',
+ 'items' => array(
+ array( // First item
+ 'item_name' => 'First item name',
+ 'item_description' => 'This is a description of the first item in the cart, it costs $9.00',
+ 'item_amount' => '9.00',
+ // 'item_tax' => '1.00',
+ 'item_quantity' => 1,
+ 'item_number' => 'XF100',
+ ),
+ array( // Second item
+ 'item_name' => 'Second Item',
+ 'item_description' => 'This is a description of the SECOND item in the cart, it costs $1.00 but there are 3 of them.',
+ 'item_amount' => '1.00',
+ // 'item_tax' => '1.00',
+ 'item_quantity' => 3,
+ 'item_number' => 'XJ100',
+ ),
+ )
+ );
+
+ return new PayPal_Purchase( $purchase_details );
+}
+
+
+
+/**
+ * Creates a PayPal Subscription Object
+ */
+function create_example_subscription() {
+
+ set_credentials();
+
+ $subscription_details = array(
+ 'initial_amount' => '10.00',
+ 'amount' => '2.00',
+ 'period' => 'Week',
+ 'frequency' => '1',
+ 'total_cycles' => '4',
+ );
+
+ return new PayPal_Subscription( $subscription_details );
+}
+
+
+function get_script_uri( $script = 'index.php' ){
+ // IIS Fix
+ if( empty( $_SERVER['REQUEST_URI'] ) )
+ $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
+
+ // Strip off query string
+ $url = preg_replace( '/\?.*$/', '', $_SERVER['REQUEST_URI'] );
+ //$url = 'http://'.$_SERVER['HTTP_HOST'].'/'.ltrim(dirname($url), '/').'/';
+ $url = 'http://'.$_SERVER['HTTP_HOST'].implode( '/', ( explode( '/', $_SERVER['REQUEST_URI'], -1 ) ) ) . '/';
+
+ return $url . $script;
+}
32 index.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Examples
+ *
+ * A few examples to demonstrate the methods of accepting payments.
+ */
+
+?>
+<html>
+<head>
+ <title>PayPal - Digital Goods for Express Checkout Examples</title>
+ <link rel="stylesheet" type="text/css" href="style.css" />
+</head>
+<body>
+ <div class="container">
+ <h1>Thanks for Dropping by!</h1>
+ <p>This library includes three examples: <a href="example-purchase.php">Simple Purchase</a>, <a href="example-subscription.php">Simple Subscription</a> and <a href="example-subscription-checkout.php">Subscription with Separate Checkout</a>.</p>
+
+ <h3>Simple Purchase</h3>
+ <p>This example demonstrates how to use the library to accept a Digital Goods payment.</p>
+ <p><a href="example-purchase.php">Try the Simple Purchase Example &raquo;</a></p>
+
+ <h3>Simple Subscription</h3>
+ <p>Create a Digital Goods Subscription by following the this example.</p>
+ <p><a href="example-subscription.php">Try the Simple Subscription Example &raquo;</a></p>
+
+ <h3>Subscription with Separate Checkout</h3>
+ <p>This example shows how to use a separate checkout page in the payment flow. Doing so greatly reduces the page load of your payment/sign-up page by requesting a checkout token from PayPal only after a visitor has committed to payment.</p>
+ <p><a href="example-subscription-checkout.php">Try the Separate Checkout Example &raquo;</a></p>
+ </div>
+</body>
+</html>
49 return.php
@@ -0,0 +1,49 @@
+<?php
+require_once( 'functions.php' );
+
+?>
+<html>
+<head>
+ <title>PayPal Recurring Payments Return Page</title>
+ <link rel="stylesheet" type="text/css" href="style.css" />
+</head>
+<body>
+ <div class="container">
+ <h2>PayPal Recurring Payments Demo</h2>
+
+ <?php // Returning from PayPal & Payment Cancelled ?>
+ <?php if( isset( $_GET['paypal'] ) && $_GET['paypal'] == 'cancel' ) : ?>
+
+ <script>if (window!=top) {top.location.replace(document.location);}</script>
+ <p>Your subscription has been cancelled. <a href="<?php echo get_script_uri(); ?>" target="_top">Try again? &raquo;</a></p>
+
+ <?php // Returning from PayPal & Payment Authorised ?>
+ <?php elseif( isset( $_GET['paypal'] ) && $_GET['paypal'] == 'paid' ) :
+
+ // Process the payment or start the Subscription
+ if( isset( $_GET['PayerID'] ) ) {
+ $paypal = create_example_purchase();
+ $response = $paypal->process_payment();
+ } else {
+ $paypal = create_example_subscription();
+ $response = $paypal->start_subscription();
+ }
+ ?>
+
+ <h3>Payment Complete!</h3>
+ <?php if( isset( $_GET['PayerID'] ) ) { ?>
+ <p>Your Transaction ID is <?php echo $response['PAYMENTINFO_0_TRANSACTIONID']; ?></p>
+ <p>You can use this Transaction ID to see the details of your subscription like so:</p>
+ <pre><code>get_transaction_details( $response['PAYMENTINFO_0_TRANSACTIONID'] );</code></pre>
+ <p><a href="<?php echo get_script_uri( 'check-profile.php?transaction_id=' . urlencode($response['PAYMENTINFO_0_TRANSACTIONID']) ) ?>" target="_top">View Transaction Details &raquo;</a></p>
+ <?php } else { ?>
+ <p>Your Payment Profile ID is <?php echo $response['PROFILEID']; ?></p>
+ <p>You can use this Profile ID to see the details of your subscription like so:</p>
+ <pre><code>get_profile_details('<?php echo $response['PROFILEID']; ?>');</code></pre>
+ <p><a href="<?php echo get_script_uri( 'check-profile.php?profile_id=' . urlencode($response['PROFILEID']) ) ?>" target="_top">Check Profile &raquo;</a></p>
+ <?php } ?>
+
+ <?php endif; ?>
+ </div>
+</body>
+</html>
27 style.css
@@ -0,0 +1,27 @@
+html, body {
+ color: #212121;
+ height: 100%;
+ width: 100%;
+ padding: 0;
+ margin:0;
+}
+div.container {
+ width: auto;
+ max-width: 520px;
+ min-height: 220px;
+ margin: 0 auto;
+ padding: 22px;
+ background-color: #fff;
+ border: 1px solid #999;
+ -webkit-border-radius: 10px;
+ -moz-border-radius: 10px;
+ border-radius: 10px;
+ -moz-box-shadow: 0 0 6px 2px #CCC;
+ -webkit-box-shadow: 0 0 6px 2px #CCC;
+ box-shadow: 0 0 6px 2px #CCC;
+ position: relative;
+ top: 15%;
+}
+pre {
+ padding: 0.5em 0.2em;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.