Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents fbe8225 + fa957de commit 339d9c964305d8847529f02b7e63a17f6b34df38 @akDeveloper committed Feb 26, 2013
@@ -16,7 +16,7 @@ class Base
/**
* @var string
*/
- const VERSION = "1.0.6";
+ const VERSION = "1.1.0-alpha";
/**
* @var string
@@ -150,8 +150,11 @@ public function isTest()
}
/**
- * @throws AktiveMerchant\Billing\Exception
+ * Accepts the anount of money in base unit and returns cants or base unit
+ * amount according to the @see $money_format propery.
*
+ * @throws \InvalidArgumentException
+ * @param $money The amount of money in base unit, not in cents.
* @access public
* @return integer|float
*/
@@ -162,7 +165,7 @@ public function amount($money)
$cents = $money * 100;
if (!is_numeric($money) || $money < 0) {
- throw new Exception('money amount must be a positive Integer in cents.');
+ throw new \InvalidArgumentException('money amount must be a positive number.');
}
return ($this->money_format() == 'cents')
@@ -171,17 +171,18 @@ public function credit($money, $identification, $options = array())
}
/**
- *
- * @param number $money
- * @param CreditCard $creditcard
- * @param array $options
+ * {@inheritdoc}
+ * Optional $options are:
+ * - 'occurrences' Number of billing occurrences or payments for the
+ * subscription. Default is 9999 for a no end date
+ * (an ongoing subscription).
*/
public function recurring($money, CreditCard $creditcard, $options=array())
{
$options = new Options($options);
Options::required(
- 'length, unit, start_date, occurrences, billing_address',
+ 'frequency, period, start_date, billing_address',
$options
);
@@ -190,6 +191,14 @@ public function recurring($money, CreditCard $creditcard, $options=array())
$options['billing_address']
);
+ if (null == $options->occurrences) {
+ $options->occurrences = '9999';
+ }
+
+ if ( null == $options->trial_occurrences) {
+ $options->trial_occurrences = 0;
+ }
+
$amount = $this->amount($money);
$ref_id = $options['order_id'];
@@ -566,12 +575,12 @@ private function arb_add_subscription($amount, $options)
<name>Subscription of {$options['billing_address']['first_name']} {$options['billing_address']['last_name']}</name>
<paymentSchedule>
<interval>
- <length>{$options['length']}</length>
- <unit>{$options['unit']}</unit>
+ <length>{$options['frequency']}</length>
+ <unit>{$options['period']}</unit>
</interval>
<startDate>{$options['start_date']}</startDate>
<totalOccurrences>{$options['occurrences']}</totalOccurrences>
- <trialOccurrences>0</trialOccurrences>
+ <trialOccurrences>{$options['trial_occurrences']}</trialOccurrences>
</paymentSchedule>
<amount>$amount</amount>
<trialAmount>0</trialAmount>
@@ -142,6 +142,8 @@ private function commit($action, $money, $parameters)
{
$url = $this->isTest() ? static::TEST_URL : static::LIVE_URL;
+ $this->getAdapter()->setOption(CURLOPT_SSLVERSION, 3);
+
$data = $this->ssl_post($url, $this->post_data($action), $parameters);
$options = array('test' => $this->isTest());
@@ -73,7 +73,7 @@ private function build_reference_sale_or_authorization_request($action, $money,
}
private function build_credit_card_request($action, $money, $credit_card, $options) {
- $default_currency = static::$default_currency;
+ $default_currency = self::$default_currency;
$bodyXml = <<<XML
<{$action}>
@@ -4,12 +4,9 @@
class PayflowUk extends Payflow
{
-
- public static $default_currency = 'GBP';
protected $partner = 'PayPalUk';
public static $supported_cardtypes = array('visa', 'master', 'american_express', 'discover', 'solo', 'switch');
public static $supported_countries = array('GB');
public static $homepage_url = 'https://www.paypal.com/uk/cgi-bin/webscr?cmd=_wp-pro-overview-outside';
public static $display_name = 'PayPal Payflow Pro (UK)';
-
}
@@ -9,6 +9,7 @@
use AktiveMerchant\Billing\Gateways\Paypal\PaypalExpressResponse;
use AktiveMerchant\Common\Country;
use AktiveMerchant\Common\Address;
+use AktiveMerchant\Common\Options;
/**
* Description of PaypalExpress
*
@@ -175,6 +176,55 @@ public function void($authorization, $options = array())
return $this->commit('DoVoid');
}
+ public function recurring($money, $options = array())
+ {
+ Options::required('start_date, period, frequency, token, description', $options);
+
+ $this->post = array();
+
+ $params = array(
+ 'METHOD' => 'CreateRecurringPaymentsProfile',
+ 'PROFILESTARTDATE' => $options['start_date'],
+ 'BILLINGPERIOD' => $options['period'],
+ 'BILLINGFREQUENCY' => $options['frequency'],
+ 'AMT' => $this->amount($money),
+ 'TOKEN' => urlencode(trim($options['token'])),
+ 'DESC' => $options['description'],
+ );
+
+ $this->add_address($options);
+
+ $this->post = array_merge(
+ $this->post,
+ $params,
+ $this->get_optional_params($options)
+ );
+
+ return $this->commit('CreateRecurringPaymentsProfile');
+
+ }
+
+ public function getRecurringDetails($profile_id)
+ {
+ $this->post = array();
+
+ $this->post['PROFILEID'] = $profile_id;
+ $this->post['METHOD'] = 'GetRecurringPaymentsProfileDetails';
+
+ return $this->commit('GetRecurringPaymentsProfileDetails');
+ }
+
+ public function setupRecurring($money, $options = array())
+ {
+
+ $this->post = array();
+ $this->post['L_BILLINGAGREEMENTDESCRIPTION0'] = $options['desc'];
+ $this->post['L_BILLINGTYPE0'] = 'RecurringPayments';
+
+ return $this->setup($money, 'Authorization', $options);
+
+ }
+
/**
* Setup Authorize and Purchase actions
*
@@ -188,6 +238,7 @@ public function void($authorization, $options = array())
*/
public function setupAuthorize($money, $options = array())
{
+ $this->post = array();
return $this->setup($money, 'Authorization', $options);
}
@@ -200,6 +251,7 @@ public function setupAuthorize($money, $options = array())
*/
public function setupPurchase($money, $options = array())
{
+ $this->post = array();
return $this->setup($money, 'Sale', $options);
}
@@ -208,8 +260,6 @@ private function setup($money, $action, $options = array())
$this->required_options('return_url, cancel_return_url', $options);
- $this->post = array();
-
$params = array(
'METHOD' => 'SetExpressCheckout',
'PAYMENTREQUEST_0_AMT' => $this->amount($money),
@@ -403,7 +453,7 @@ public function get_details_for($token, $payer_id)
);
$this->post = array_merge($this->post, $params);
- return $this->commit($this->urlize($this->post));
+ return $this->commit(null);
}
/**
@@ -425,7 +475,6 @@ protected function post_data($action)
);
if ( $this->post['METHOD'] == 'SetExpressCheckout'
- || $this->post['METHOD'] == 'GetExpressCheckoutDetails'
) {
$params['PAYMENTREQUEST_0_PAYMENTACTION'] = $action;
}
@@ -23,6 +23,11 @@
/**
* Creates a profile using a valid credit card so can charge it in a given
* period of time.
+ * $options array must have following info:
+ * - 'start_date' The date the subscription begins
+ * - 'period' Unit for billing during the subscription period. Varies
+ * according gateway
+ * - 'frequency' Number of billing periods that make up one billing cycle
*
* @param number $money The amount to to charge
* @param Creditcard $creditcard A creditcard instance with a valid number.
@@ -79,10 +79,55 @@
echo '<pre>';
print_r($response);
echo '</pre>';
- } elseif (isset( $_GET['token'] ) ) {
+ } elseif ( isset($_GET['recurring']) ) {
+ $options = array(
+ 'return_url' => 'http://127.0.0.1/Aktive-Merchant/test/paypal_express/index.php',
+ 'cancel_return_url' => 'http://127.0.0.1/Aktive-Merchant/test/paypal_express/index.php?cancel=1',
+ 'desc' =>'Golden plan subscription',
+ 'items' => array(
+ array(
+ 'name' => 'Golden Plan',
+ 'description' => 'Golden plan subscription',
+ 'unit_price' => 30,
+ 'quantity' => 1,
+ 'id' => '1245345'
+ ),
+ ),
+ 'billing_address' => array(
+ 'address1' => '1234 Penny Lane',
+ 'city' => 'Jonsetown',
+ 'state' => 'NC',
+ 'country' => 'US',
+ 'zip' => '23456'
+ ),
+ 'ip' => '127.0.0.1',
+ );
+ $amount = $_POST['amount'];
+ $startdate = new \DateTime("{$_POST['year']}-{$_POST['month']}-{$_POST['day']}");
+
+ $response = $gateway->setupRecurring($amount, $options);
+
+ if ($response->success()) {
+ die ( header('Location: '. $gateway->urlForToken( $response->token() )) );
+ } else {
+ echo $response->message();
+ }
+
+ echo '<pre>';
+ //print_r($response);
+ print_r($startdate);
+ echo '</pre>';
+ } elseif ( isset($_GET['details']) ) {
+
+ $response = $gateway->getRecurringDetails('I-BGKDETHHBHU1');
- $response = $gateway->get_details_for( $_GET['token'], $_GET['PayerID']);
+ echo '<pre>';
+ print_r($response);
+ echo '</pre>';
+ } 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
@@ -92,13 +137,41 @@
* make sure you have store somewhere token and payer_id values
* ex. $_SESSION or Database
*/
-
- $response = $gateway->authorize($response->amount());
+ $opt = array(
+ 'start_date' => '2013-2-16T0:0:0',
+ 'period' => 'Month',
+ 'frequency' => 1,
+ 'token' => $_GET['token'],
+ 'description' => 'Golden plan subscription',
+ 'items' => array(
+ array(
+ 'name' => 'Golden Plan',
+ 'description' => 'Golden plan subscription',
+ 'unit_price' => 30,
+ 'quantity' => 1,
+ 'id' => '1245345'
+ ),
+ ),
+ 'billing_address' => array(
+ 'address1' => '1234 Penny Lane',
+ 'city' => 'Jonsetown',
+ 'state' => 'NC',
+ 'country' => 'US',
+ 'zip' => '23456'
+ ),
+ 'email' => 'john_doe@example.com'
+ );
+
+ $response = $gateway->recurring(30, $opt);
+
if ( $response->success() ) {
echo 'Success payment!';
} else {
echo $response->message();
}
+ echo '<pre>';
+ print_r($response);
+ echo '</pre>';
}
} catch (Exception $exc) {
echo $exc->getMessage();
@@ -140,3 +213,39 @@
<input type="submit" />
</fieldset>
</form>
+
+<form method="post" action="/Aktive-Merchant/test/paypal_express/index.php?recurring=1">
+ <fieldset>
+ <legend>Recurring</legend>
+ <label for="amount">Amount</label>
+ <input type="text" name="amount" value="30" id="amount" />
+ <label for="startdate">Start Date</label>
+ <select id="year" name="year">
+ <?php $year = date("Y", time());?>
+ <?php for ($i = $year; $i < $year+10; $i++): ?>
+ <option value="<?php echo $i?>"><?php echo $i?></option>
+ <?php endfor; ?>
+ </select>
+ <select id="month" name="month">
+ <?php for ($i = 1; $i <= 12; $i++): ?>
+ <option value="<?php echo $i?>"><?php echo $i?></option>
+ <?php endfor; ?>
+ </select>
+ <select id="day" name="day">
+ <?php for ($i = 1; $i <= 31 ; $i++): ?>
+ <option value="<?php echo $i?>"><?php echo $i?></option>
+ <?php endfor; ?>
+ </select>
+ <label for="period">Billing Period</label>
+ <select id="period" name="period">
+ <option value="Day">Day</option>
+ <option value="Week">Week</option>
+ <option value="SemiMonth">Semi Month</option>
+ <option value="Month">Month</option>
+ <option value="Year">Year</option>
+ </select>
+ <label for="frequency">Frequency</label>
+ <input type="text" name="frequency" value="1" id="frequency" />
+ <input type="submit" />
+ </fieldset>
+</form>
@@ -66,9 +66,9 @@ public function setUp()
'first_name' => 'John' . $this->gateway->generateUniqueId(),
'last_name' => 'Smith'
),
- 'length' => 11,
- 'unit' => 'months',
- 'start_date' => date("Y-m-d", time()),
+ 'frequency' => 11,
+ 'period' => 'months',
+ 'start_date' => date("Y-m-d", strtotime('tomorrow')),
'occurrences' => 1
);
}
@@ -219,7 +219,7 @@ private function successful_recurring_request($name, $firstname, $order_id)
<length>11</length>
<unit>months</unit>
</interval>
- <startDate>'.date("Y-m-d", time()).'</startDate>
+ <startDate>'.date("Y-m-d", strtotime('tomorrow')).'</startDate>
<totalOccurrences>1</totalOccurrences>
<trialOccurrences>0</trialOccurrences>
</paymentSchedule>

0 comments on commit 339d9c9

Please sign in to comment.