public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { include_once dirname(__FILE__) . '/SOPGClassicMerchantClient.php'; $client = new SOPGClassicMerchantClient($this->getConfig('testing') ? self::TEST_API_URL : self::LIVE_API_URL); $mtid = $invoice->public_id; //$this->generateMtid(); // SEE par.2 if ($invoice->first_total > 1000) { throw new InvalidArgumentException('The maximum amount value of dispositions is 1000.00'); } // see par.2 $request = array($this->getConfig('login'), $this->getConfig('password'), $mtid, null, sprintf('%.2f', $invoice->first_total), $invoice->currency, urlencode($this->getReturnUrl()), urlencode($this->getPluginUrl('cancelpaysafecart') . "?id=" . $invoice->getSecureId('CANCEL')), $invoice->getUserId(), urlencode($this->getPluginUrl()), null); $this->logRequest($request); $response = call_user_func_array(array($client, 'createDisposition'), $request); $this->logResponse(get_object_vars($response)); if ($response->resultCode != 0 || $response->errorCode != 0) { // SEE par.4 $result->setErrorMessages(array('Transaction could not be initiated due to connection problems.')); //$result->setErrorMessages(array('Error during request to paysafecard server')); // see par.4 return; } $a = new Am_Paysystem_Action_Redirect($this->getConfig('testing') ? self::TEST_REDIRECT_URL : self::LIVE_REDIRECT_URL); $a->mid = $response->mid; $a->mtid = $mtid; $a->amount = sprintf('%.2f', $invoice->first_total); $a->currency = $invoice->currency; $result->setAction($a); }
public function calculateStartDate($paymentDate, Invoice $invoice) { if ($paymentDate instanceof DateTime) { $paymentDate = $paymentDate->format('Y-m-d'); } $ret = array(); $setting = $this->getStartDate(); $callArgs = array(); if (in_array(self::SD_PRODUCT, $setting)) { $callArgs['product_id'] = $this->product_id; } if (in_array(self::SD_GROUP, $setting)) { $callArgs['renewal_group'] = $this->renewal_group; } if (in_array(self::SD_PAYMENT, $setting)) { $ret[] = $paymentDate; } if (in_array(self::SD_FIXED, $setting) && $this->start_date_fixed) { $ret[] = $this->start_date_fixed; } if (count($callArgs)) { $callArgs['user_id'] = $invoice->getUserId(); $ret[] = $this->getDi()->accessTable->getLastExpire($callArgs); } $ret = array_filter($ret); if (!$ret) { $ret[] = $this->getDi()->sqlDate; } return max($ret); }
public function calculateStartDate($paymentDate, Invoice $invoice) { if ($paymentDate instanceof DateTime) { $paymentDate = $paymentDate->format('Y-m-d'); } $ret = array(); $setting = $this->getStartDate(); $callArgs = array(); if (in_array(self::SD_PRODUCT, $setting)) { $callArgs['product_id'] = $this->product_id; } if (in_array(self::SD_GROUP, $setting)) { $callArgs['renewal_group'] = $this->renewal_group; } if (in_array(self::SD_PAYMENT, $setting)) { $ret[] = $paymentDate; } if (in_array(self::SD_FIXED, $setting) && $this->start_date_fixed) { $ret[] = $this->start_date_fixed; } if (count($callArgs)) { $callArgs['user_id'] = $invoice->getUserId(); $ret[] = $this->getDi()->accessTable->getLastExpire($callArgs); } foreach (array(self::SD_WEEKDAY_SUN, self::SD_WEEKDAY_MON, self::SD_WEEKDAY_TUE, self::SD_WEEKDAY_WED, self::SD_WEEKDAY_THU, self::SD_WEEKDAY_FRI, self::SD_WEEKDAY_SAT) as $sd) { if (in_array($sd, $setting)) { preg_match('/w([0-6])/i', $sd, $matches); $need = $matches[1]; /* @var $date DateTime */ $date = $this->getDi()->dateTime; $now = $date->format('w'); $diff = (7 + $need - $now) % 7; $date->modify("+{$diff} days"); $ret[] = $date->format('Y-m-d'); } } foreach (array(self::SD_MONTH_1, self::SD_MONTH_15) as $sd) { if (in_array($sd, $setting)) { preg_match('/m([0-6]+)/i', $sd, $matches); $need = $matches[1]; /* @var $date DateTime */ $date = $this->getDi()->dateTime; $now = $date->format('d'); $m = $now < $need ? 0 : 1; $date->modify("+{$m} months"); $ret[] = $date->format('Y-m-' . sprintf('%02d', $need)); } } $ret = array_filter($ret); if (!$ret) { $ret[] = $this->getDi()->sqlDate; } return max($ret); }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $vars = array('x_version' => '3.1', 'x_login' => $this->getConfig('login'), 'x_test_request' => $this->getTestRequestStatus(), 'x_show_form' => 'PAYMENT_FORM', 'x_amount' => $price = sprintf('%.2f', $invoice->first_total), 'x_receipt_link_url' => $this->getPluginUrl('thanks'), 'x_relay_url' => $this->getPluginUrl('thanks'), 'x_relay_response' => 'TRUE', 'x_cancel_url' => $this->getCancelUrl(), 'x_invoice_num' => $invoice->public_id, 'x_cust_id' => $invoice->getUserId(), 'x_description' => $invoice->getLineDescription(), 'x_fp_sequence' => $invoice->public_id, 'x_fp_timestamp' => $tstamp = time(), 'x_address' => $invoice->getStreet(), 'x_city' => $invoice->getCity(), 'x_country' => $invoice->getCountry(), 'x_state' => $invoice->getState(), 'x_zip' => $invoice->getZip(), 'x_email' => $invoice->getEmail(), 'x_first_name' => $invoice->getFirstName(), 'x_last_name' => $invoice->getLastName(), 'x_fp_hash' => hash_hmac('md5', $this->getConfig('login') . "^" . $invoice->public_id . "^" . $tstamp . "^" . $price . "^", $this->getConfig('tkey'))); $action = new Am_Paysystem_Action_Redirect($this->getRedirectUrl() . "?" . http_build_query($vars, '', '&')); $result->setAction($action); }