Login   Register  
PHP Classes
elePHPant
Icontem

File: test/paypal_express/index.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Andreas Kollaros  >  Aktive Merchant  >  test/paypal_express/index.php  >  Download  
File: test/paypal_express/index.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: Aktive Merchant
Common interface to process payments with gateways
Author: By
Last change:
Date: 3 years ago
Size: 1,750 bytes
 

Contents

Class file image Download
<?php
require_once('../../lib/merchant.php');
require_once(
'../login.php');

Merchant_Billing_Base::mode('test');

$gateway = new Merchant_Billing_PaypalExpress( array(
  
'login' => PAYPAL_LOGIN,
  
'password' => PAYPAL_PASS,
  
'signature' => PAYPAL_SIG,
  
'currency' => 'EUR'
  
)
);

try {

  if ( isset(
$_GET['pay']) ) {

    
$response $gateway->setup_purchase($_POST['amount'], array(
      
'return_url' => 'http://localhost/merchant/test/paypal_express/index.php',
      
'cancel_return_url' => 'http://localhost/merchant/test/paypal_express/index.php?cancel=1',
      )
    );


    die ( 
header('Location: '$gateway->url_for_token$response->token() )) );

  } elseif (isset(
$_GET['cancel'])) {

    echo 
'Transaction Canceled!<br />';

  } elseif (isset( 
$_GET['token'] ) ) {

    
$response $gateway->get_details_for$_GET['token'], $_GET['PayerID']);

    
/**
     * You can modify transaction amount according to paypal ship address
     * or even render a form to allow customer choose shipping methods and
     * additional costs.
     * NOTE: if you execute $gateway->authorize() or $gateway->purchase() to a
     * different page than you executed $gateway->get_details_for()
     * make sure you have store somewhere token and payer_id values
     * ex. $_SESSION or Database
     */

    
$response $gateway->purchase($response->amount());
    if ( 
$response->success() ) {
      echo 
'Success payment!';
    } else {
      echo 
$response->message();
    }
  }
} catch (
Exception $exc) {
  echo 
$exc->getMessage();
}

?>
<form method="post" action="/merchant/test/paypal_express/index.php?pay=1">
  <label for="amount">Amount</label>
  <input type="text" name="amount" value="1" id="amount" />
  <input type="submit" />
</form>