public function __construct($options = array()) { $this->required_options('login, password, signature', $options); $this->options = $options; if (isset($options['version'])) { $this->version = $options['version']; } if (isset($options['currency'])) { self::$default_currency = $options['currency']; } }
/** * Get the authorization URL * * @param ComSubscriptionsDomainPaymentPayload $payload * @param string $return_url The return url * @param string $cancel_url The cancel url * * @return string */ public function getAuthorizationURL(ComSubscriptionsDomainPaymentPayload $payload, $return_url, $cancel_url) { $gateway = new Merchant_Billing_PaypalExpress($this->_gateway_config); $options = array('return_url' => (string) $return_url, 'cancel_return_url' => (string) $cancel_url, 'NOSHIPPING' => 1, 'LANDINGPAGE' => 'Billing'); if ($payload->getRecurring()) { $options['billing_type'] = 'RecurringPayments'; $options['billing_agreement_description'] = $payload->description; } $response = $gateway->setup_purchase($payload->getTotalAmount(), $options); if ($response->success()) { return $gateway->url_for_token($response->TOKEN); } else { throw new KException($response->message()); } }
<?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/Aktive-Merchant/test/paypal_express/index.php', 'cancel_return_url' => 'http://localhost/Aktive-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) {