[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/externals/wepay/iframe_demoapp/ -> checkout.php (source)

   1  <?php
   2  /**
   3   * This PHP script helps you do the iframe checkout
   4   *
   5   */
   6  
   7  
   8  /**
   9   * Put your API credentials here:
  10   * Get these from your API app details screen
  11   * https://stage.wepay.com/app
  12   */
  13  $client_id = "PUT YOUR CLIENT_ID HERE";
  14  $client_secret = "PUT YOUR CLIENT_SECRET HERE";
  15  $access_token = "PUT YOUR ACCESS TOKEN HERE";
  16  $account_id = "PUT YOUR ACCOUNT_ID HERE"; // you can find your account ID via list_accounts.php which users the /account/find call
  17  
  18  /** 
  19   * Initialize the WePay SDK object 
  20   */
  21  require  '../wepay.php';
  22  Wepay::useStaging($client_id, $client_secret);
  23  $wepay = new WePay($access_token);
  24  
  25  /**
  26   * Make the API request to get the checkout_uri
  27   * 
  28   */
  29  try {
  30      $checkout = $wepay->request('/checkout/create', array(
  31              'account_id' => $account_id, // ID of the account that you want the money to go to
  32              'amount' => 100, // dollar amount you want to charge the user
  33              'short_description' => "this is a test payment", // a short description of what the payment is for
  34              'type' => "GOODS", // the type of the payment - choose from GOODS SERVICE DONATION or PERSONAL
  35              'mode' => "iframe", // put iframe here if you want the checkout to be in an iframe, regular if you want the user to be sent to WePay
  36          )
  37      );
  38  } catch (WePayException $e) { // if the API call returns an error, get the error message for display later
  39      $error = $e->getMessage();
  40  }
  41  
  42  ?>
  43  
  44  <html>
  45      <head>
  46      </head>
  47      
  48      <body>
  49          
  50          <h1>Checkout:</h1>
  51          
  52          <p>The user will checkout here:</p>
  53          
  54          <?php if (isset($error)): ?>
  55              <h2 style="color:red">ERROR: <?php echo $error ?></h2>
  56          <?php else: ?>
  57              <div id="checkout_div"></div>
  58          
  59              <script type="text/javascript" src="https://stage.wepay.com/js/iframe.wepay.js">
  60              </script>
  61              
  62              <script type="text/javascript">
  63              WePay.iframe_checkout("checkout_div", "<?php echo $checkout->checkout_uri ?>");
  64              </script>
  65          <?php endif; ?>
  66      
  67      </body>
  68      
  69  </html>


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1