/mvc/components/paypal
[return to app]1
<?php
2 /**
3 * PayPal payment interface
4 */
5 class paypalComponent {
6 /**
7 * Sets the configuration for the PayPal payment page
8 *
9 * @var array
10 */
11 public $config = array('rm' => 2, //2 - POST back payment info to the return URL, 0 = GET, 1 = no-return-data
12 'undefined_quantity' => 0, //1 allows buyers to specify the quantity.
13 'no_note' => 1, //1 = hides notes box
14 'no_shipping' => 1, //1 = no shipping prompt
15 'cpp_headerborder_color' => '333333',
16 'cpp_payflow_color' => '333333');
17
18 /**
19 * Additional configuration settings - the default values are dynamic so they cannot be set in the property
default
20 */
21 public function __construct() {
22 $baseUrl = 'http://' . $_SERVER['HTTP_HOST'] . '/' . mvc::$controller;
23 $this->config = array_merge($this->config, array(
24 'cbt' => get::$config->SITE_NAME, //Sets "Return to Merchant" button text on PayPal Payment-Complete
page
25 'return' => $baseUrl . '/complete', //post-payment URL
26 'notify_url' => $baseUrl . '/complete', //payment notification URL
27 'cancel_return' => $baseUrl, //payment cancelled URL
28 'shopping_url' => $baseUrl //continue browsing/return URL
29 ));
30 }
31
32 /**
33 * Flag to use sandbox (for testing) instead of live payment system
34 *
35 * @var boolean
36 */
37 public $useSandbox = false;
38
39 /**
40 * Send a user to the PayPal payment page
41 *
42 * @param array $fields
43 */
44 public function goToPay(array $fields = array()) {
45 $fields = array_merge($fields, $this->config, array(
46 'cmd' => '_cart',
47 'upload' => 1, //required to use 3rd party cart
48 'business' => get::$config->PAYPAL_EMAIL,
49 'rm' => 2, //2 - POST back payment info to the return URL, 0 = GET, 1 = no-return-data
50 ));
51 $subdomain = (!$this->useSandbox ? 'www' : 'sandbox');
52 $url = 'https://' . $subdomain . '.paypal.com/cgi-bin/webscr?' . http_build_query($fields);
53 load::redirect($url);
54 }
55 }