/** * Return a payment method * * @param string $token The authorization token * @param string $country If the country is known then it will set the country code * * @return ComSubscriptionsDomainPaymentMethodToken */ public function getExpressPaymentMethod($token, &$country = null) { $gateway = new Merchant_Billing_PaypalExpress($this->_gateway_config); $response = $gateway->get_details_for($token, ''); $method = new ComSubscriptionsDomainPaymentMethodToken('Paypal', array('payer_id' => $response->payer_id(), 'token' => $token)); $country = $response->COUNTRYCODE; return $method; }
<?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) {