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); }
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) { $a = new Am_Paysystem_Action_Redirect(self::URL); $a->merchant = $this->getConfig('merchant'); $a->trans_id = $invoice->public_id; $a->amount = $invoice->first_total; $a->callback = $this->getPluginUrl('thanks'); $a->digest = $this->calculateDigest($a); $a->bill_addr_1 = $invoice->getStreet(); $a->bill_city = $invoice->getCity(); $a->bill_country = $invoice->getCountry(); $a->bill_email = $invoice->getEmail(); $a->bill_name = $invoice->getName(); $a->bill_post_code = $invoice->getZip(); $a->bill_state = $invoice->getState(); $a->bill_tel = $invoice->getPhone(); $a->currency = $invoice->currency; $a->options = "cb_post=true,md_flds=trans_id:amount:callback"; if ($invoice->rebill_times) { // Recurring payment; $a->repeat = sprintf("%s/%s/%s:%s", gmdate('Ymd', strtotime($invoice->calculateRebillDate(1))), $this->getPeriod($invoice->second_period), $invoice->rebill_times == IProduct::RECURRING_REBILLS ? '-1' : $invoice->rebill_times, $invoice->second_total); $a->repeat_callback = $a->callback; } if ($this->getConfig('testing')) { $a->test_status = 'true'; } $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; }