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 _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(); }
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"); }
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); }
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; } }
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; }
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"); }
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); }
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); }
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); }
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); }
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); }
function createRecurringPaymentProfile(Invoice $invoice, CcRecord $cc = null, $token = null, $payerId = null) { if (!$cc && !$token) { throw new Am_Exception_Paysystem("Either [token] or [cc] must be specified for " . __METHOD__); } $periodConvert = array(Am_Period::DAY => 'Day', Am_Period::MONTH => 'Month', Am_Period::YEAR => 'Year'); $this->addPostParameter('METHOD', 'CreateRecurringPaymentsProfile'); if ($token) { $this->addPostParameter('TOKEN', $token); $this->addPostParameter('PAYERID', $payerId); } $this->addPostParameter('DESC', $invoice->getTerms()); $this->addPostParameter('PROFILESTARTDATE', gmdate('Y-m-d\\TH:i:s.00\\Z', strtotime($invoice->calculateRebillDate(1) . ' 00:00:01'))); $this->addPostParameter('PROFILEREFERENCE', $invoice->getRandomizedId('site')); //$this->addPostParameter('MAXFAILEDPAYMENTS', ''); //$this->addPostParameter('AUTOBILLOUTAMT', 'AddToNextBilling'); $p = new Am_Period($invoice->first_period); $pp = $periodConvert[$p->getUnit()]; if (!$pp) { throw new Am_Exception_Configuration("Could not find billing unit for invoice#{$invoice->invoice_id}.first_period: {$invoice->first_period}"); } /// first period - removed as handled with START_DATE //$this->addPostParameter('TRIALBILLINGPERIOD', $pp); //$this->addPostParameter('TRIALBILLINGFREQUENCY', $p->getCount()); //$this->addPostParameter('TRIALTOTALBILLINGCYCLES', '1'); //$this->addPostParameter('TRIALAMT', $invoice->second_total); // bill at the end of trial period // it may take up to 24hours to process it! so enabled only for credit card payments if ($cc && $invoice->first_total > 0) { $this->addPostParameter('INITAMT', $invoice->first_total); } // bill right now /// second period $p = new Am_Period($invoice->second_period); $pp = $periodConvert[$p->getUnit()]; if (!$pp) { throw new Am_Exception_Configuration("Could not find billing unit for invoice#{$invoice->invoice_id}.second_period: {$invoice->second_period}"); } $this->addPostParameter('BILLINGPERIOD', $pp); $this->addPostParameter('BILLINGFREQUENCY', $p->getCount()); if ($invoice->rebill_times != IProduct::RECURRING_REBILLS) { $this->addPostParameter('TOTALBILLINGCYCLES', $invoice->rebill_times); } $this->addPostParameter('AMT', $invoice->second_total - $invoice->second_tax); // bill at end of each payment period $this->addPostParameter('TAXAMT', $invoice->second_tax); $this->addPostParameter('CURRENCYCODE', $invoice->currency); // @todo $this->addPostParameter('NOTIFYURL', $this->plugin->getPluginUrl('ipn')); $i = 0; foreach ($invoice->getItems() as $item) { /* @var $item InvoiceItem */ $this->addPostParameter("L_PAYMENTREQUEST_0_NAME{$i}", $item->item_title); $this->addPostParameter("L_PAYMENTREQUEST_0_NUMBER{$i}", $item->item_id); $this->addPostParameter("L_PAYMENTREQUEST_0_QTY{$i}", $item->qty); $i++; } $this->addPostParameter('L_BILLINGTYPE0', 'RecurringPayments'); $this->addPostParameter('L_BILLINGAGREEMENTDESCRIPTION0', $invoice->getTerms()); if ($cc) { $this->setCC($invoice, $cc); } if ($this->plugin->getConfig('send_shipping')) { $this->setShippingAddress($invoice); } return $this; }
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); }
public function validateSource() { // We "complete" the request by acknowledging that specific user $response = $this->_sendRequest('/redirect_flows/' . $this->getUniqId() . '/actions/complete', array('data' => array('session_token' => Zend_Session::getId()))); if ($response->getStatus() !== 200) { return false; } $response = json_decode($response->getBody(), true); if (!(isset($response['redirect_flows']) && isset($response['redirect_flows']['links']) && isset($response['redirect_flows']['links']['mandate']))) { return false; } $invoice = $this->loadInvoice($this->findInvoiceId()); $mandateId = $response['redirect_flows']['links']['mandate']; $this->_updateInvoice('mandate', $mandateId); if (!empty($invoice->rebill_times) && intval($invoice->rebill_times) > 0) { // First payment is made outside the subscription, right away (one off payment): $paymentParams = array('payments' => array('currency' => $invoice->currency, 'amount' => intval(floatval($invoice->first_total) * 100), 'description' => $invoice->getLineDescription(), 'metadata' => array('user' => $invoice->getEmail(), 'invoice_id' => $invoice->public_id), 'links' => array('mandate' => $mandateId))); // One time payment of first_total $response = $this->_sendRequest('/payments', $paymentParams); if ($response->getStatus() !== 201) { return false; } $response = json_decode($response->getBody(), true); $invoice->addPayment(new Am_Paysystem_Transaction_Gocardlesspro_Payment($this->getPlugin(), $response['payments'], $this->response, $this->invokeArgs)); // Start subscription at interval + n $first_period = new Am_Period($invoice->first_period); $date_period = new DateTime($first_period->addTo(date('Y-m-d')), new DateTimeZone('UTC')); // Subscription of second_total $subscriptionParams = array('start_at' => $date_period->format('Y-m-d'), 'links' => array('mandate' => $mandateId), 'metadata' => array('user' => $invoice->getEmail(), 'invoice_id' => $invoice->public_id)); $period = empty($invoice->second_period) ? $invoice->first_period : $invoice->second_period; if ($period === Am_Period::MAX_SQL_DATE) { $subscriptionParams['interval_unit'] = 'yearly'; } else { $am_period = new Am_Period($period); switch ($am_period->getUnit()) { case 'm': $interval_unit = 'monthly'; break; case 'y': $interval_unit = 'yearly'; break; } $subscriptionParams['interval_unit'] = $interval_unit; } if (!empty($invoice->second_total)) { $subscriptionParams['amount'] = intval(floatval($invoice->second_total) * 100); } else { $subscriptionParams['amount'] = intval(floatval($invoice->first_total) * 100); } $subscriptionParams['name'] = $invoice->getLineDescription(); $subscriptionParams['currency'] = $invoice->currency; $subscriptionParams['count'] = intval($invoice->rebill_times); if ($subscriptionParams['count'] > 1000) { $subscriptionParams['count'] = 1000; } if ($subscriptionParams['interval_unit'] === 'monthly') { $subscriptionParams['day_of_month'] = 5; } $response = $this->_sendRequest('/subscriptions', array('subscriptions' => $subscriptionParams)); if ($response->getStatus() !== 201) { return false; } $response = json_decode($response->getBody(), true); $this->_updateInvoice('subscription', $response['subscriptions']['id']); } else { // One time payment only $paymentParams = array('payments' => array('currency' => $invoice->currency, 'amount' => intval(floatval($invoice->first_total) * 100), 'description' => $invoice->getLineDescription(), 'metadata' => array('user' => $invoice->getEmail(), 'invoice_id' => $invoice->public_id), 'links' => array('mandate' => $mandateId))); // One time payment of first_total $response = $this->_sendRequest('/payments', $paymentParams); if ($response->getStatus() !== 201) { return false; } $response = json_decode($response->getBody(), true); $invoice->addPayment(new Am_Paysystem_Transaction_Gocardlesspro_Payment($this->getPlugin(), $response['payments'], $this->response, $this->invokeArgs)); } $invoice->updateStatus(); return true; }
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 _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); }
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}"); }
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"); }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $u = $invoice->getUser(); $a = new Am_Paysystem_Action_Redirect(self::API_URL); /* */ $params = array('aid' => $this->getConfig('aid'), 'portalid' => $this->getConfig('portalid'), 'mode' => $this->getConfig('testing') ? 'test' : 'live', 'encoding' => 'UTF-8', 'clearingtype' => 'cc', 'reference' => $invoice->public_id, 'customerid' => $invoice->user_id, 'invoiceid' => $invoice->public_id, 'param' => $invoice->public_id, 'successurl' => $this->getReturnUrl(), 'backurl' => $this->getCancelUrl()); //Parameter („createaccess“) $first_period = new Am_Period($invoice->first_period); $params['request'] = 'createaccess'; $params['productid'] = $invoice->getItem(0)->getBillingPlanData('payone_product_id'); // + + N..7 ID for the offer $params['amount_trail'] = $invoice->first_total * 100; // - + N..6 Total price of all items during the initial term. Must equal the sum (quantity * price) of all items for the initial term (in the smallest currency unit, e.g. Cent). $params['period_unit_trail'] = strtoupper($first_period->getUnit()); // - + Default Time unit for initial term, possible values: Y: Value in years M: Value in months D: Value in days $params['period_length_trail'] = $first_period->getCount(); // - + N..4 Duration of the initial term. Can only be used in combination with period_unit_trail. $params['id_trail'] = $invoice->getItem(0)->billing_plan_id; // + + AN..100 Item number (initial term) $params['no_trail'] = 1; // + + N..5 Quantity (initial term) $params['pr_trail'] = $invoice->first_total * 100; // + + N..7 Unit price of the item in smallest currency unit (initial term) $params['de_trail'] = $invoice->getItem(0)->item_description; // + + AN..255 Description (initial term) $params['ti_trail'] = $invoice->getItem(0)->item_title; // + + AN..100 Title (initial term) //$params['va_trail'] = ''; // - + N..4 VAT rate (% or bp) (initial term) value < 100 = percent value > 99 = basis points if ($invoice->second_total > 0) { $second_period = new Am_Period($invoice->second_period); $params['amount_recurring'] = $invoice->second_total * 100; // - + N..6 Total price of all items during the subsequent term. Must equal the sum (quantity * price) of all items for the subsequent term (in the smallest currency unit, e.g. Cent). $params['period_unit_recurring'] = strtoupper($second_period->getUnit()); // - + Default Time unit for subsequent term, possible values: Y: Value in years M: Value in months D: Value in days N: only if no subsequent term $params['period_length_recurring'] = $second_period->getCount(); // - + N..4 Duration of the subsequent term. Can only be used in combination with period_unit_recurring. $params['id_recurring'] = $invoice->getItem(0)->billing_plan_id; // - + AN..100 Item number (subsequent term) $params['no_recurring'] = 1; // - + N..5 Quantity (subsequent term) $params['pr_recurring'] = $invoice->second_total * 100; // - + N..7 Unit price of the item in smallest currency unit (subsequent term) $params['de_recurring'] = $invoice->getItem(0)->item_description; // - + AN..255 Description (subsequent term) $params['ti_recurring'] = $invoice->getItem(0)->item_title; // - + AN..100 Title (subsequent term) //$params['va_recurring'] = ''; // - + N..4 VAT rate (% or bp) (subsequent term) value < 100 = percent value > 99 = basis points ///// } /* //Parameter ( „pre-/authorization“ ) $params['request'] = 'authorization'; $params['amount'] = $invoice->first_total * 100; $params['currency'] = $invoice->currency; $params['it'] = 'goods'; //For BSV: Item type $params['id'] = ''; //Your item no. $params['pr'] = $invoice->first_total * 100; //Price in Cent $params['no'] = 1; //Quantity $params['de'] = ''; //Item description //$params['va'] = ''; //VAT (optional) ///// */ ksort($params); $a->hash = strtolower(md5(implode('', $params) . $this->getConfig('secret_key'))); //Hash value (see chapter 3.1.4) //Parameter ( personal data ) $params['firstname'] = $u->name_f; //AN..50 First name $params['lastname'] = $u->name_l; //AN..50 Surname //$params['company'] = ''; //AN..50 Company $params['street'] = $u->street; //AN..50 Street $params['zip'] = $u->zip; //AN..10 Postcode $params['city'] = $u->city; //AN..50 City $params['country'] = $u->country; //Default Country (ISO 3166) $params['email'] = $u->email; //AN..50 Email address $params['language'] = 'en'; //Language indicator (ISO 639) //If the language is not transferred, the browser //language will be used. For a non-supported //language, English will be used. ///// foreach ($params as $k => $v) { $a->addParam($k, $v); } $result->setAction($a); }
public function findInvoiceId() { if ($id = $this->getPlugin()->getDi()->db->selectCell("\n SELECT i.public_id\n FROM ?_invoice_payment ip\n LEFT JOIN ?_invoice i USING (invoice_id)\n WHERE transaction_id = ?\n ", $this->_order['ReferenceId'])) { return $id; } $itemId = $this->_order['ItemId'] ? $this->_order['ItemId'] : $this->_order['Items'][0]['ItemId']; $billing_plans = $this->getPlugin()->getDi()->billingPlanTable->findByData(Am_Paysystem_Selz::SELZ_ITEM_ID_FIELD, $itemId); $bpIds = array(); foreach ($billing_plans as $bp) { $bpIds[] = $bp->pk(); } if (empty($bpIds) || !$this->_order['BuyerEmail']) { return; } $id = $this->getPlugin()->getDi()->db->selectCell("\n SELECT ii.invoice_public_id\n FROM ?_invoice_item ii\n LEFT JOIN ?_invoice i ON i.invoice_id=ii.invoice_id\n LEFT JOIN ?_user u ON u.user_id=i.user_id\n WHERE\n ii.billing_plan_id IN (?a)\n AND i.status = ?d\n AND i.paysys_id = ?\n AND u.email = ?\n ORDER BY ii.invoice_id DESC\n ", $bpIds, Invoice::PENDING, 'selz', $this->_order['BuyerEmail']); if ($id) { $invoice = $this->loadInvoice($id); $item = $invoice->getItem(0); $qty = $this->_order['Quantity'] ? $this->_order['Quantity'] : $this->_order['Items'][0]['Quantity']; if ($item->qty != $qty) { $period = new Am_Period($item->first_period); $newPeriod = new Am_Period($period->getCount() * $qty, $period->getUnit()); $item->first_period = (string) $newPeriod; $item->qty = $qty; $item->_calculateTotal(); $item->update(); $invoice->calculate(); $invoice->first_period = (string) $newPeriod; $invoice->update(); } } return $id; }
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; } }
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'); }
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"); }