Beispiel #1
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $a = new Am_Paysystem_Action_Redirect(self::URL);
     $result->setAction($a);
     $a->ok_receiver = $this->getConfig('wallet_id');
     $a->ok_invoice = $invoice->public_id;
     $a->ok_currency = strtoupper($invoice->currency);
     if (!(double) $invoice->second_total) {
         $a->ok_kind = 'payment';
         $a->ok_item_1_name = $invoice->getLineDescription();
         $a->ok_item_1_price = $invoice->first_total;
     } else {
         $a->ok_kind = 'subscription';
         $a->ok_s_title = $invoice->getLineDescription();
         if ($invoice->first_total != $invoice->second_total || $invoice->first_period != $invoice->second_period) {
             $p = new Am_Period($invoice->first_period);
             $a->ok_s_trial_price = $invoice->first_total;
             $a->ok_s_trial_cycle = sprintf('%d %s', $p->getCount(), strtoupper($p->getUnit()));
         }
         $p = new Am_Period($invoice->second_period);
         $a->ok_s_regular_price = $invoice->second_total;
         $a->ok_s_regular_cycle = sprintf('%d %s', $p->getCount(), strtoupper($p->getUnit()));
         $a->ok_s_regular_count = $invoice->rebill_times == IProduct::RECURRING_REBILLS ? 0 : $invoice->rebill_times;
     }
     $a->ok_payer_first_name = $invoice->getFirstName();
     $a->ok_payer_last_name = $invoice->getLastName();
     $a->ok_payer_street = $invoice->getStreet();
     $a->ok_payer_city = $invoice->getCity();
     $a->ok_payer_state = $invoice->getState();
     $a->ok_payer_zip = $invoice->getZip();
     $a->ok_payer_country = $invoice->getCountry();
     $a->ok_ipn = $this->getPluginUrl('ipn');
     $a->ok_return_success = $this->getReturnUrl();
     $a->ok_return_fail = $this->getCancelUrl();
 }
Beispiel #2
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $u = $invoice->getUser();
     $a = new Am_Paysystem_Action_Redirect(self::LIVE_URL);
     $a->pay_to_email = $this->getConfig('business');
     $a->pay_from_email = $u->email;
     $a->transaction_id = $invoice->public_id;
     $a->amount = $invoice->first_total;
     $a->currency = $invoice->currency;
     $a->language = $u->lang;
     $a->return_url = $this->getReturnUrl();
     $a->cancel_url = $this->getCancelUrl();
     $a->status_url = $this->getPluginUrl('ipn');
     $a->detail1_text = $invoice->getLineDescription();
     $a->firstname = $u->name_f;
     $a->lastname = $u->name_l;
     $a->address = $u->street;
     $a->postal_code = $u->zip;
     $a->city = $u->city;
     $a->state = $u->state;
     $a->country = $u->country;
     if ($invoice->second_total > 0) {
         $a->rec_amount = $invoice->second_total;
         $periods = array('m' => 'month', 'y' => 'year', 'd' => 'day');
         $second_period = new Am_Period($invoice->second_period);
         $a->rec_cycle = $periods[$second_period->getUnit()];
         $a->rec_period = $second_period->getCount();
         $a->rec_start_date = date('Y/m/d', strtotime($invoice->calculateRebillDate(1)));
         $a->rec_status_url = $this->getPluginUrl('ipn');
     }
     $result->setAction($a);
 }
Beispiel #3
0
 function getDays(Am_Period $period)
 {
     switch ($period->getUnit()) {
         case Am_Period::DAY:
             return $period->getCount();
         case Am_Period::MONTH:
             return $period->getCount() * 30;
         case Am_Period::YEAR:
             return $period->getCount() * 365;
     }
 }
Beispiel #4
0
 function getPeriod($period)
 {
     $p = new Am_Period($period);
     switch ($p->getUnit()) {
         case Am_Period::DAY:
             if ($p->getCount() == 1) {
                 return 'daily';
             }
             if ($p->getCount() == 7) {
                 return 'weekly';
             }
             break;
         case Am_Period::MONTH:
             if ($p->getCount() == 1) {
                 return 'monthly';
             }
             if ($p->getCount() == 3) {
                 return 'quarterly';
             }
             if ($p->getCount() == 6) {
                 return 'half-yearly';
             }
             break;
         case Am_Period::YEAR:
             if ($p->getCount() == 1) {
                 return 'yearly';
             }
         default:
             // nop. exception
     }
     throw new Am_Exception_Paysystem_NotConfigured("Unable to convert period [{$period}] to PayPoint-compatible." . "Please contact webmaster for more information about this issue");
 }
Beispiel #5
0
 protected function buildSubscriptionParams(Am_Paysystem_Action_Redirect $a, Invoice $invoice)
 {
     $a->ap_purchasetype = 'subscription';
     $a->ap_trialamount = $invoice->first_total;
     $period = new Am_Period();
     $period->fromString($invoice->first_period);
     $a->ap_trialtimeunit = $this->translatePeriodUnit($period->getUnit());
     $a->ap_trialperiodlength = $period->getCount();
     $a->ap_amount = $invoice->second_total;
     $period = new Am_Period();
     $period->fromString($invoice->second_period);
     $a->ap_timeunit = $this->translatePeriodUnit($period->getUnit());
     $a->ap_periodlength = $period->getCount();
     $a->ap_periodcount = $invoice->rebill_times == IProduct::RECURRING_REBILLS ? 0 : $invoice->rebill_times;
 }
Beispiel #6
0
 public function period2Wp($period)
 {
     $p = new Am_Period($period);
     switch ($p->getUnit()) {
         case Am_Period::DAY:
             return array($p->getCount(), 1);
         case Am_Period::MONTH:
             return array($p->getCount(), 3);
         case Am_Period::YEAR:
             return array($p->getCount(), 4);
         default:
             // nop. exception
     }
     throw new Am_Exception_Paysystem_NotConfigured("Unable to convert period [{$period}] to Worldpay-compatible." . "Must be number of days, months or years");
 }
Beispiel #7
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $periods = array('y' => 'years', 'm' => 'months', 'd' => 'days', 'fixed' => 'years');
     $u = $invoice->getUser();
     $a = new Am_Paysystem_Action_Form(self::LIVE_URL);
     $a->language = $this->getDi()->app->getDefaultLocale();
     $order = array();
     $a->__set('order[shop_id]', $this->getConfig('shop_id'));
     $a->__set('order[currency]', $invoice->currency);
     $a->__set('order[email]', $u->email);
     $a->__set('order[success_url]', $this->getReturnUrl($request));
     $a->__set('order[cancel_url]', $this->getCancelUrl($request));
     $a->__set('order[fail_url]', $this->getCancelUrl($request));
     $a->__set('order[notification_url]', $this->getPluginUrl('ipn'));
     $a->__set('order[billing_address_attributes][first_name]', $u->name_f);
     $a->__set('order[billing_address_attributes][last_name]', $u->name_l);
     $a->__set('order[billing_address_attributes][address]', $u->street);
     $a->__set('order[billing_address_attributes][country]', $u->country);
     $a->__set('order[billing_address_attributes][city]', $u->city);
     $a->__set('order[billing_address_attributes][zip]', $u->zip);
     $a->__set('order[billing_address_attributes][state]', $u->state);
     $a->__set('order[billing_address_attributes][zip]', $u->zip);
     //recurring
     if (!is_null($invoice->second_period)) {
         $a->__set('order[subscription_attributes][description]', $invoice->getLineDescription());
         $a->__set('order[subscription_attributes][trial_amount]', $invoice->first_total * 100);
         $first_period = new Am_Period($invoice->first_period);
         $a->__set('order[subscription_attributes][trial_interval_unit]', $periods[$first_period->getUnit()]);
         $a->__set('order[subscription_attributes][trial_interval]', $first_period->getCount() == Am_Period::MAX_SQL_DATE ? '25' : $first_period->getCount());
         $a->__set('order[subscription_attributes][amount]', $invoice->second_total * 100);
         $second_period = new Am_Period($invoice->second_period);
         $a->__set('order[subscription_attributes][interval_unit]', $periods[$second_period->getUnit()]);
         $a->__set('order[subscription_attributes][interval]', $second_period->getCount() == Am_Period::MAX_SQL_DATE ? '25' : $second_period->getCount());
         if ($invoice->rebill_times) {
             $a->__set('order[subscription_attributes][rebill_limit]', $invoice->rebill_times);
         }
     } else {
         $a->__set('order[line_items_attributes][][name]', $invoice->getLineDescription());
         $a->__set('order[line_items_attributes][][amount]', $invoice->first_total * 100);
         $a->__set('order[line_items_attributes][][quantity]', 1);
         $a->__set('order[tax_amount]', $invoice->first_tax * 100);
     }
     $a->__set('order[tracking_params_attributes][][name]', 'invoice_id');
     $a->__set('order[tracking_params_attributes][][value]', $invoice->public_id);
     $a->filterEmpty();
     $a->__set('order[signature]', hash('sha256', $sha = $a->__get('order[subscription_attributes][trial_amount]') . $a->__get('order[line_items_attributes][][amount]') . $a->__get('order[cancel_url]') . $a->__get('order[currency]') . $a->__get('order[email]') . $a->__get('order[fail_url]') . $a->__get('order[success_url]') . $invoice->public_id . $a->__get('order[subscription_attributes][amount]') . $a->__get('order[subscription_attributes][description]') . $a->__get('order[subscription_attributes][interval]') . $a->__get('order[subscription_attributes][interval_unit]') . $a->__get('order[subscription_attributes][rebill_limit]') . $a->__get('order[subscription_attributes][trial_amount]') . $a->__get('order[subscription_attributes][trial_interval]') . $a->__get('order[subscription_attributes][trial_interval_unit]') . $this->getConfig('secret_key')));
     $result->setAction($a);
 }
Beispiel #8
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $a = new Am_Paysystem_Action_Redirect(self::URL_SUBSCRIPTION);
     $params = array('key' => $this->getConfig('key'), 'uid' => $invoice->getUser()->pk(), 'widget' => $this->getConfig('widget'), 'email' => $invoice->getUser()->email, 'amount' => $invoice->first_total, 'currencyCode' => $invoice->currency, 'ag_name' => $invoice->getLineDescription(), 'ag_external_id' => $invoice->public_id, 'ag_type' => $invoice->first_period == Am_Period::MAX_SQL_DATE ? self::TYPE_FIXED : self::TYPE_SUBSCRIPTION, 'ag_recurring' => $invoice->second_total > 0 ? 1 : 0, 'ag_trial' => $invoice->second_total > 0 && $invoice->first_total != $invoice->second_total ? 1 : 0, 'sign_version' => 2, 'success_url' => $this->getReturnUrl(), 'pingback_url' => $this->getPluginUrl('ipn'));
     if ($params['ag_type'] == self::TYPE_SUBSCRIPTION) {
         $period = new Am_Period($invoice->first_period);
         $params = array_merge($params, array('ag_period_length' => $period->getCount(), 'ag_period_type' => $this->trUnit($period->getUnit())));
     }
     if ($params['ag_trial']) {
         $period = new Am_Period($invoice->second_period);
         $params = array_merge($params, array('ag_post_trial_period_length' => $period->getCount(), 'ag_post_trial_period_type' => $this->trUnit($period->getUnit()), 'ag_post_trial_external_id' => $invoice->public_id, 'post_trial_amount' => $invoice->second_total, 'post_trial_currencyCode' => $invoice->currency, 'ag_post_trial_name' => $invoice->getLineDescription(), 'hide_post_trial_good' => 1));
     }
     $params['sign'] = $this->calculateSignature($params, $this->getConfig('secret'));
     foreach ($params as $k => $v) {
         $a->addParam($k, $v);
     }
     $result->setAction($a);
 }
 function process(User $user, array $r)
 {
     $times = unserialize($r['wp_optimizemember_paid_registration_times']);
     $max = max($times);
     foreach ($times as $level => $time) {
         if (!($pid = $this->_translateProduct($level))) {
             continue;
         }
         $bpId = Am_Di::getInstance()->productTable->load($pid)->default_billing_plan_id;
         $fisrtPeriod = Am_Di::getInstance()->billingPlanTable->load($bpId)->first_period;
         $period = new Am_Period($fisrtPeriod);
         $this->payment[$pid] = array('start' => sqlTime($time), 'stop' => $period->addTo(sqlTime($time)));
         if ($time == $max) {
             $lastProduct = $pid;
         }
     }
     $this->payment[$lastProduct]['subscr_id'] = $r['wp_optimizemember_subscr_id'];
     $this->user = $user;
     return $this->doWork();
 }
Beispiel #10
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $u = $invoice->getUser();
     $a = new Am_Paysystem_Action_Redirect($this->getConfig('testing') ? self::SANDBOX_URL : self::LIVE_URL);
     $a->ps_store_id = $this->getConfig('ps_store_id');
     $a->hpp_key = $this->getConfig('hpp_key');
     $a->charge_total = sprintf('%.2f', $invoice->first_total);
     $a->cust_id = $invoice->public_id;
     $a->email = $u->email;
     $a->shipping_cost = sprintf('%.2f', $invoice->first_shipping);
     $i = 1;
     foreach ($invoice->getItems() as $item) {
         $a->{'id' . $i} = $item->item_id;
         $a->{'description' . $i} = $item->item_title;
         $a->{'quantity' . $i} = $item->qty;
         $a->{'price' . $i} = $item->first_price;
         $a->{'subtotal' . $i} = $item->first_total;
         $i++;
     }
     $a->bill_first_name = $u->name_f;
     $a->bill_last_name = $u->name_l;
     $a->bill_address_one = $u->street;
     $a->bill_city = $u->city;
     $a->bill_state_or_province = $u->state;
     $a->bill_postal_code = $u->zip;
     $a->bill_country = $u->country;
     if ($invoice->second_total > 0) {
         $periods = array('m' => 'month', 'y' => 'year', 'd' => 'day', 'w' => 'week');
         $second_period = new Am_Period($invoice->second_period);
         $a->recurUnit = $periods[$second_period->getUnit()];
         $a->recurPeriod = $second_period->getCount();
         $a->recurStartNow = $invoice->first_total > 0 ? 'true' : 'false';
         $a->doRecur = 1;
         $a->recurStartDate = date('Y/m/d', strtotime($invoice->calculateRebillDate(1)));
         $a->recurAmount = sprintf('%.2f', $invoice->second_total);
         $a->recurNum = $invoice->rebill_times;
     }
     $result->setAction($a);
 }
Beispiel #11
0
 /**
  * Function returns product subscription terms as text
  * @return string
  */
 function getString()
 {
     if (is_null($this->first_price) || !strlen($this->first_period)) {
         return "";
     }
     $price1 = $this->first_price;
     $price2 = $this->second_price;
     if ($price1 instanceof Am_Currency) {
         $price1 = $price1->getValue();
     }
     if ($price2 instanceof Am_Currency) {
         $price2 = $price2->getValue();
     }
     $c1 = $price1 > 0 ? $this->getCurrency($this->first_price) : 'Free';
     $c2 = $price2 > 0 ? $this->getCurrency($this->second_price) : 'free';
     $p1 = new Am_Period($this->first_period);
     $p2 = new Am_Period($this->second_period);
     $ret = (string) $c1;
     if (!$p1->isLifetime()) {
         if ($this->rebill_times) {
             $ret .= $p1->getText(" for first %s", true);
         } else {
             $ret .= $p1->getText(" for %s");
         }
     }
     if ($this->rebill_times) {
         if (!$p1->equalsTo($p2) || $price1 != $price2) {
             $ret .= ", then ";
         } else {
             $ret = "";
         }
         $ret .= (string) $c2 . $p2->getText(" for each %s");
         if ($this->rebill_times < IProduct::RECURRING_REBILLS) {
             $ret .= sprintf(", for %d installments", $this->rebill_times);
         }
     }
     return preg_replace('/[ ]+/', ' ', $ret);
 }
Beispiel #12
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $user = $invoice->getUser();
     $period = new Am_Period($invoice->first_period);
     $a = new Am_Paysystem_Action_Redirect(self::GATEWAY);
     $a->pslid = $this->getConfig('pslid');
     $a->reference_number = self::REF_PREFIX . $invoice->public_id;
     $a->frequency_type = strtoupper($period->getUnit());
     if ($invoice->first_total != $invoice->second_total) {
         $a->first_amount = $invoice->first_total * 100;
     }
     $a->regular_amount = $invoice->second_total * 100;
     $a->payer_reference = sprintf('U%07d', $user->pk());
     $a->first_name = $user->name_f;
     $a->last_name = $user->name_l;
     $a->address_1 = $user->street;
     $a->address_2 = $user->street2;
     $a->town = $user->city;
     $a->county = $this->getDi()->countryTable->getTitleByCode($user->country);
     $a->postcode = $user->zip;
     $a->email_address = $user->email;
     $result->setAction($a);
 }
Beispiel #13
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $vars = array('merchantid' => $this->getConfig('merchant_id'), 'txnid' => $invoice->public_id, 'amount' => $invoice->first_total, 'ccy' => $invoice->currency, 'description' => strlen($desc = $invoice->getLineDescription()) > 128 ? substr($desc, 0, 125) . "..." : $desc, 'email' => $invoice->getUser()->email);
     if ($invoice->rebill_times) {
         if ($this->invoice->first_total > 0 && $this->invoice->first_total != $this->invoice->second_total) {
             throw new Am_Exception_InternalError('If product has no free trial first price must be the same second price');
         }
         if ($this->invoice->first_total > 0 && $this->invoice->first_period != $this->invoice->second_period) {
             throw new Am_Exception_InternalError('If product has no free trial first period must be the same second period');
         }
         $p = new Am_Period($invoice->first_period);
         switch ($p->getUnit()) {
             case Am_Period::DAY:
                 $vars['period'] = 'daily';
                 $vars['frequency'] = $invoice->rebill_times;
                 break;
             case Am_Period::MONTH:
                 $vars['period'] = 'monthly';
                 $vars['frequency'] = $invoice->rebill_times;
                 break;
             case Am_Period::YEAR:
                 $vars['period'] = 'monthly';
                 $vars['frequency'] = 12 * $invoice->rebill_times;
                 break;
             default:
                 throw new Am_Exception_Paysystem_NotConfigured("Unable to convert period [{$invoice->first_period}] to Dragonpay-compatible. Must be number of days, months or years");
         }
         $url = $this->getConfig('test_mode') ? self::URL_RECUR_PAY_TEST : self::URL_RECUR_PAY_LIVE;
     } else {
         $url = $this->getConfig('test_mode') ? self::URL_PAY_TEST : self::URL_PAY_LIVE;
     }
     $vars['digest'] = $this->getDigest(join(':', $vars));
     $this->logRequest($vars);
     $a = new Am_Paysystem_Action_Redirect($url . "?" . http_build_query($vars, '', '&'));
     $result->setAction($a);
 }
Beispiel #14
0
 function getPeriod(Invoice $invoice)
 {
     $tz = date_default_timezone_get();
     date_default_timezone_set('EST5EDT');
     $first_period = new Am_Period($invoice->first_period);
     $second_period = new Am_Period($invoice->second_period);
     $periods = array('1d' => 'daily', '7d' => 'weekly', '14d' => 'biweekly', '1m' => 'monthly', '2m' => 'bimonthly', '3m' => 'quarterly', '1y' => 'yearly', Am_Period::MAX_SQL_DATE => 'once');
     $period = $periods[$invoice->second_period];
     if (empty($period)) {
         Am_Di::getInstance()->errorLogTable->log("WEPAY. {$invoice->second_period} is not supported");
         date_default_timezone_set($tz);
         throw new Am_Exception_InternalError();
     }
     if ($invoice->rebill_times == IProduct::RECURRING_REBILLS) {
         date_default_timezone_set($tz);
         return array($period, '');
     }
     $end = $first_period->addTo(date('Y-m-d'));
     for ($i = 0; $i < $invoice->rebill_times; $i++) {
         $end = $second_period->addTo($end);
     }
     date_default_timezone_set($tz);
     return array($period, $end);
 }
Beispiel #15
0
 public function getCycle(Invoice $invoice)
 {
     $p = new Am_Period();
     $p->fromString($invoice->second_period);
     switch ($p->getUnit()) {
         case Am_Period::DAY:
             return $p->getCount();
         case Am_Period::MONTH:
             return $p->getCount() * 30;
         case Am_Period::YEAR:
             return $p->getCount() * 356;
         default:
             throw new Am_Exception_InputError('Incorrect product second period: ' . $p->getUnit());
     }
 }
 public function period2Co($period, $rebill_times = 1)
 {
     $p = new Am_Period($period);
     $c = $p->getCount() * $rebill_times;
     switch ($p->getUnit()) {
         case Am_Period::DAY:
             if (!($c % 7)) {
                 return sprintf('%d Week', $c / 7);
             } else {
                 throw new Am_Exception_Paysystem_NotConfigured("2Checkout does not supported per-day billing, period must be in weeks (=7 days), months, or years");
             }
         case Am_Period::MONTH:
             return sprintf('%d Month', $c);
         case Am_Period::YEAR:
             return sprintf('%d Year', $c);
     }
     throw new Am_Exception_Paysystem_NotConfigured("Unable to convert period [{$period}] to 2Checkout-compatible." . "Must be number of weeks, months or years");
 }
Beispiel #17
0
 /**
  * @access protected
  */
 function updateRebillDate()
 {
     $date = null;
     $c = $this->getPaymentsCount();
     if ($this->first_total <= 0) {
         $c++;
     }
     // first period is "fake" because it was free trial
     //if ($c < $this->getExpectedPaymentsCount()) // not yet done with rebills
     if ($this->rebill_times > $c - 1) {
         // we count starting from first payment date, we rely on tm_started field here
         if ($this->first_total <= 0) {
             list($date, ) = explode(' ', $this->tm_started);
         } else {
             $date = $this->getAdapter()->selectCell("SELECT MIN(dattm) FROM ?_invoice_payment WHERE invoice_id=?d", $this->invoice_id);
         }
         $date = date('Y-m-d', strtotime($date));
         $period1 = new Am_Period($this->first_period);
         $date = $period1->addTo($date);
         $period2 = new Am_Period($this->second_period);
         for ($i = 1; $i < $c; $i++) {
             $date = $period2->addTo($date);
         }
     }
     $this->updateQuick('rebill_date', $date);
     $this->rebill_date = $date;
 }
Beispiel #18
0
 function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     if (!$this->getConfig('business')) {
         throw new Am_Exception_Configuration("There is a configuration error in [paypal] plugin - no [business] e-mail configured");
     }
     $a = new Am_Paysystem_Action_Redirect('https://' . $this->domain . '/cgi-bin/webscr');
     $result->setAction($a);
     $a->business = $this->getConfig('business');
     $a->return = $this->getReturnUrl();
     $a->notify_url = $this->getPluginUrl('ipn');
     $a->cancel_return = $this->getCancelUrl();
     $a->item_name = html_entity_decode($invoice->getLineDescription(), null, 'UTF-8');
     $a->no_shipping = $invoice->hasShipping() ? 0 : 1;
     $a->shipping = $invoice->first_shipping;
     $a->currency_code = strtoupper($invoice->currency);
     $a->no_note = 1;
     $a->invoice = $invoice->getRandomizedId();
     $a->bn = 'CgiCentral.aMemberPro';
     $a->first_name = $invoice->getFirstName();
     $a->last_name = $invoice->getLastName();
     $a->address1 = $invoice->getStreet();
     $a->city = $invoice->getCity();
     $a->state = $invoice->getState();
     $a->zip = $invoice->getZip();
     $a->country = $invoice->getCountry();
     $a->charset = 'utf-8';
     if ($lc = $this->getConfig('lc')) {
         $a->lc = $lc;
     }
     $a->rm = 2;
     if ($invoice->rebill_times) {
         $a->cmd = '_xclick-subscriptions';
         $a->sra = 1;
         if ($invoice->rebill_times == 1) {
             $a->src = 0;
         } else {
             $a->src = 1;
             //Ticket #HPU-80211-470: paypal_r plugin not passing the price properly (or at all)?
             if ($invoice->rebill_times != IProduct::RECURRING_REBILLS) {
                 $a->srt = $invoice->rebill_times;
             }
         }
         /** @todo check with rebill times = 1 */
         $a->a1 = $invoice->first_total;
         $p = new Am_Period($invoice->first_period);
         $a->p1 = $p->getCount();
         $a->t1 = $this->getPeriodUnit($p->getUnit());
         $a->tax1 = $invoice->first_tax;
         $a->a3 = $invoice->second_total;
         $p = new Am_Period($invoice->second_period);
         $a->p3 = $p->getCount();
         $a->t3 = $this->getPeriodUnit($p->getUnit());
         $a->tax3 = $invoice->second_tax;
     } else {
         $a->cmd = '_xclick';
         $a->amount = $invoice->first_total - $invoice->first_tax - $invoice->first_shipping;
         $a->tax = $invoice->first_tax;
     }
 }
Beispiel #19
0
 /**
  * Add period to rebill_date;
  * If current rebill_date is null or is in the past , script will use today's date(function will be executed only when payment is added to system). So next rebill date should be set to rebill_date + payment_period;
  * When second parameter ($date) will be passed, it will be used instead of rebill_date in order to handle prorated access situations.
  *
  * @param type $isFirst period that will be added;
  * @param type $date  - date that will be used instead of current rebill_date setting;
  *
  */
 function addToRebillDate($isFirst, $date = null)
 {
     // If we are done with rebills just set date to null;
     if ($this->getPaymentsCount() >= $this->getExpectedPaymentsCount()) {
         $this->updateQuick('rebill_date', null);
         $this->rebill_date = null;
         return;
     }
     $today = $this->getDi()->dateTime->format('Y-m-d');
     // Handle situation when customer try to rebill outdated payments;
     // In this situation rebill_date should be set to today.
     if (is_null($this->rebill_date) || $this->rebill_date < $today) {
         $this->rebill_date = $today;
     }
     if (!is_null($date)) {
         $this->rebill_date = $date;
     }
     $period = new Am_Period($isFirst ? $this->first_period : $this->second_period);
     $this->rebill_date = $period->addTo($this->rebill_date);
     $this->updateSelectedFields('rebill_date');
 }
Beispiel #20
0
 public function getPeriod($period)
 {
     $p = new Am_Period($period);
     switch ($p->getUnit()) {
         case Am_Period::DAY:
             return $p->getCount() . 'D';
         case Am_Period::MONTH:
             return $p->getCount() . 'M';
         case Am_Period::YEAR:
             return $p->getCount() * 12 . 'M';
         default:
             // nop. exception
     }
     throw new Am_Exception_Paysystem_NotConfigured("Unable to convert period [{$period}] to Hipay-compatible." . "Must be number of days, months or years");
 }
Beispiel #21
0
 public function addAccess(Am_Event $event)
 {
     /* @var $user User */
     $user = $event->getUser();
     $product_ids = $this->getConfig('product_ids');
     if (!$product_ids) {
         return;
     }
     foreach ($product_ids as $id) {
         $product = Am_Di::getInstance()->productTable->load($id);
         //calucalet access dates
         $invoice = Am_Di::getInstance()->invoiceRecord;
         $invoice->setUser($user);
         $invoice->add($product);
         $begin_date = $product->calculateStartDate(Am_Di::getInstance()->sqlDate, $invoice);
         $p = new Am_Period($product->getBillingPlan()->first_period);
         $expire_date = $p->addTo($begin_date);
         $access = Am_Di::getInstance()->accessRecord;
         $access->setForInsert(array('user_id' => $user->pk(), 'product_id' => $product->pk(), 'begin_date' => $begin_date, 'expire_date' => $expire_date, 'qty' => 1));
         $access->insert();
         Am_Di::getInstance()->emailTemplateTable->sendZeroAutoresponders($user, $access);
     }
 }
Beispiel #22
0
 function __toString()
 {
     return sprintf('<div class="input_period">' . '<input type="text" name="%s[c]" value="%s" size=10 id="%s"> ' . '<select name="%s[u]" size="1" id="%s">' . Am_Controller::renderOptions($this->options, $this->period->getCount() != Am_Period::MAX_SQL_DATE ? $this->period->getUnit() : 'lifetime') . '</select></div>', $this->getName(), $this->period->getCount(), $this->getId() . '-c', $this->getName(), $this->getId() . '-u');
 }
Beispiel #23
0
 function addAccessAfterCreate($p_b, $user)
 {
     list($product_id, $billing_plan_id) = explode('_', $p_b);
     $invoice = $this->getDi()->invoiceRecord;
     $invoice->setUser($user);
     $product = $this->getDi()->productTable->load($product_id);
     $product->setBillingPlan($billing_plan_id);
     $invoice->add($product);
     $begin_date = $product->calculateStartDate($this->getDi()->sqlDate, $invoice);
     $p = new Am_Period($product->getBillingPlan()->first_period);
     $expire_date = $p->addTo($begin_date);
     $access = $this->getDi()->accessRecord;
     $access->begin_date = $begin_date;
     $access->expire_date = $expire_date;
     $access->user_id = $user->user_id;
     $access->product_id = $product_id;
     return $access->insert();
 }
Beispiel #24
0
 /**
  * Create account in aMember for user who is logged in facebook. 
  */
 function createAccount()
 {
     /* Search for account by email address */
     $user = $this->getDi()->userTable->findFirstByEmail($this->getFbProfile('email'));
     if (empty($user)) {
         // Create account for user;
         $user = $this->getDi()->userRecord;
         $user->email = $this->getFbProfile('email');
         $user->name_f = $this->getFbProfile('first_name');
         $user->name_l = $this->getFbProfile('last_name');
         $user->generateLogin();
         $user->generatePassword();
         $user->insert();
     }
     $user->data()->set(self::FACEBOOK_UID, $this->getFbProfile('id'))->update();
     if ($product_id = $this->getConfig('add_access')) {
         $product = $this->getDi()->productTable->load($product_id);
         $billingPlan = $this->getDi()->billingPlanTable->load($product->default_billing_plan_id);
         $access = $this->getDi()->accessRecord;
         $access->product_id = $product_id;
         $access->begin_date = $this->getDi()->sqlDate;
         $period = new Am_Period($billingPlan->first_period);
         $access->expire_date = $period->addTo($access->begin_date);
         $access->user_id = $user->pk();
         $access->insert();
     }
     return $user;
 }
Beispiel #25
0
 public function getRebillType(Invoice $invoice)
 {
     $res = array();
     $first_period = new Am_Period($invoice->first_period);
     $res[] = $this->rebill_type_map[$invoice->second_period];
     $res[] = $invoice->second_total;
     if ($first_period->getUnit() == 'd') {
         $res[] = $first_period->getCount();
     }
     return implode('-', $res);
 }
Beispiel #26
0
 public function isNotAcceptableForInvoice(Invoice $invoice)
 {
     if ($invoice->rebill_times && $invoice->rebill_times != IProduct::RECURRING_REBILLS) {
         return 'Incorrect Rebill Times setting!';
     }
     if ($invoice->second_total > 0 && $invoice->second_total != $invoice->first_total) {
         return 'First & Second price must be the same in invoice!';
     }
     if ($invoice->second_period > 0 && $invoice->second_period != $invoice->first_period) {
         return 'First & Second period must be the same in invoice!';
     }
     if ($invoice->rebill_times) {
         $p = new Am_Period();
         $p->fromString($invoice->first_period);
         if ($p->getUnit() == Am_Period::MONTH && $p->getCount() == 1) {
             return;
         }
         if ($p->getUnit() == Am_Period::DAY && $p->getCount() == 7) {
             return;
         }
         return "Incorrect billing terms. Only monthly and weekly payments are supported";
     }
 }
 public function calculateAccessDatesAction()
 {
     $this->getDi()->authAdmin->getUser()->checkPermission('grid_access', 'insert');
     $invoice = $this->getDi()->invoiceRecord;
     $invoice->setUser($this->getDi()->userTable->load($this->user_id));
     $product = $this->getDi()->productTable->load($this->getRequest()->getParam('product_id'));
     $invoice->add($product);
     $begin_date = $product->calculateStartDate($this->getDi()->sqlDate, $invoice);
     $p = new Am_Period($product->getBillingPlan()->first_period);
     $expire_date = $p->addTo($begin_date);
     $this->ajaxResponse(array('begin_date' => $begin_date, 'expire_date' => $expire_date));
 }
Beispiel #28
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $u = $invoice->getUser();
     if (!is_null($invoice->second_period)) {
         $a = new Am_Paysystem_Action_Redirect($url = ($this->getConfig('testing') ? self::SANDBOX_URL : self::LIVE_URL) . '/connect/subscriptions/new');
         $coef = 1;
         if ($invoice->second_period == Am_Period::MAX_SQL_DATE) {
             $interval_unit = 'month';
             $interval_length = 12 * (2037 - date('Y'));
         } else {
             $second_period = new Am_Period($invoice->second_period);
             switch ($second_period->getUnit()) {
                 case 'd':
                     $interval_unit = 'day';
                     break;
                 case 'm':
                     $interval_unit = 'month';
                     break;
                 case 'y':
                     $interval_unit = 'month';
                     $coef = 12;
                     break;
             }
             $interval_length = $second_period->getCount();
         }
         $first_period = new Am_Period($invoice->first_period);
         $start_at = new DateTime($first_period->addTo(date('Y-m-d')), new DateTimeZone('UTC'));
         $payment_details = array('amount' => $invoice->second_total, 'interval_length' => $interval_length * $coef, 'interval_unit' => $interval_unit, 'name' => $invoice->getLineDescription(), 'start_at' => $start_at->format('Y-m-d\\TH:i:s\\Z'));
         if ($invoice->rebill_times != IProduct::RECURRING_REBILLS) {
             $payment_details['interval_count'] = $invoice->rebill_times;
         }
         if (doubleval($invoice->first_total) > 0) {
             $payment_details['setup_fee'] = $invoice->first_total;
         }
     } else {
         $a = new Am_Paysystem_Action_Redirect($url = ($this->getConfig('testing') ? self::SANDBOX_URL : self::LIVE_URL) . '/connect/bills/new');
         $payment_details = array('amount' => $invoice->first_total, 'name' => $invoice->getLineDescription());
     }
     $user_details = array('first_name' => $u->name_f, 'last_name' => $u->name_l, 'email' => $u->email);
     $payment_details['merchant_id'] = $this->getConfig('merchant_id');
     ksort($payment_details);
     ksort($user_details);
     if (is_null($invoice->second_period)) {
         foreach ($payment_details as $v => $k) {
             $a->__set("bill[{$v}]", $k);
         }
         foreach ($user_details as $v => $k) {
             $a->__set("bill[user][{$v}]", $k);
         }
     }
     $a->cancel_uri = $this->getCancelUrl();
     $a->client_id = $this->getConfig('app_id');
     $a->nonce = $this->generate_nonce();
     $a->redirect_uri = $this->getDi()->config->get('root_url') . "/payment/gocardless/thanks";
     $a->state = $invoice->public_id;
     if (!is_null($invoice->second_period)) {
         foreach ($payment_details as $v => $k) {
             $a->__set("subscription[{$v}]", $k);
         }
         foreach ($user_details as $v => $k) {
             $a->__set("subscription[user][{$v}]", $k);
         }
     }
     $date = new DateTime(null, new DateTimeZone('UTC'));
     $a->timestamp = $date->format('Y-m-d\\TH:i:s\\Z');
     $url = parse_url($a->getUrl());
     $a->signature = hash_hmac('sha256', $url['query'], $this->getConfig('app_secret'));
     $result->setAction($a);
 }
Beispiel #29
0
 public function formatPeriod(Am_Period $period, $format = "%s", $skip_one_c = false)
 {
     switch ($period->getUnit()) {
         case 'd':
             $uu = $period->getCount() == 1 ? ___('day') : ___('days');
             break;
         case 'm':
             $uu = $period->getCount() == 1 ? ___('month') : ___('months');
             break;
         case 'y':
             $uu = $period->getCount() == 1 ? ___('year') : ___('years');
             break;
         case Am_Period::FIXED:
             if ($period->getCount() == Am_Period::MAX_SQL_DATE) {
                 return " for lifetime";
             }
             return " up to " . amDate($period->getCount());
     }
     $cc = $period->getCount();
     if ($period->getCount() == 1) {
         $cc = $skip_one_c ? '' : 'one';
     }
     return sprintf($format, "{$cc} {$uu}");
 }
 /**
  * Add access period for current product based on information from incoming paysystem transaction
  * @throws Am_Exception_Db_NotUnique
  */
 public function addAccessPeriod($isFirstPayment, Invoice $invoice, Am_Paysystem_Transaction_Abstract $transaction, $beginDate, $invoicePaymentId)
 {
     if ($this->item_type != 'product') {
         return;
     }
     // if that is not a product then no access
     $a = $this->getDi()->accessRecord;
     $a->setDisableHooks(true);
     $a->begin_date = $beginDate;
     $p = new Am_Period($isFirstPayment ? $this->first_period : $this->second_period);
     $a->invoice_id = $this->invoice_id;
     $recurringType = $transaction->getPlugin()->getRecurringType();
     if (in_array($recurringType, array(Am_Paysystem_Abstract::REPORTS_EOT, Am_Paysystem_Abstract::REPORTS_NOTHING))) {
         $a->expire_date = Am_Period::RECURRING_SQL_DATE;
     } else {
         $a->expire_date = $p->addTo($a->begin_date);
     }
     $a->product_id = $this->item_id;
     $a->user_id = $invoice->user_id;
     $a->transaction_id = $transaction->getUniqId();
     $a->invoice_payment_id = $invoicePaymentId;
     $a->insert();
 }