Example #1
0
 /**
  * Init call to webservice or return form params
  * 
  * @see http://www.onebip.com/website/docs/Onebip_API.pdf
  * @param Payment_Invoice $invoice
  */
 public function singlePayment(Payment_Invoice $invoice)
 {
     $data = array();
     $data['username'] = $this->getParam('username');
     $data['description'] = $invoice->getTitle();
     $data['price'] = $invoice->getTotalWithTax() * 100;
     $data['currency'] = $invoice->getCurrency();
     $data['command'] = 'standard_pay';
     $data['item_code'] = $invoice->getId();
     $data['return_url'] = $this->getParam('return_url');
     $data['notify_url'] = $this->getParam('notify_url');
     $data['cancel_url'] = $this->getParam('cancel_url');
     $c = $invoice->getBuyer();
     $data['customer_email'] = $c->getEmail();
     $data['customer_firstname'] = $c->getFirstName();
     $data['customer_lastname'] = $c->getLastName();
     if ($c->getPhone()) {
         $data['customer_cell'] = $c->getPhone();
     }
     if ($c->getCountry()) {
         $data['customer_country'] = $c->getCountry();
     }
     if ($this->testMode) {
         $data['debug'] = 1;
         $data['debug_url'] = $this->getParam('notify_url');
     }
     $data['logo_url'] = $this->getParam('logo_url');
     return $data;
 }
 /**
  * Return form params
  * @see http://www.2checkout.com/community/blog/category/knowledge-base/tech-support/3rd-party-carts/parameter-sets
  * @param Payment_Invoice $invoice
  */
 public function singlePayment(Payment_Invoice $invoice)
 {
     $b = $invoice->getBuyer();
     $full_name = $b->getFirstName() . ' ' . $b->getLastName();
     //Used to specify an approved URL on-the-fly, but is limited to the same domain that is used for your 2Checkout account, otherwise it will fail. This parameter will over-ride any URL set on the Site Management page.
     $data['x_receipt_link_URL'] = $this->getParam('return_url');
     $data['return_url'] = $this->getParam('notify_url');
     $data['sid'] = $this->getParam('vendor_nr');
     $data['mode'] = '2CO';
     $data['total'] = $this->moneyFormat($invoice->getTotalWithTax());
     $data['fixed'] = 1;
     $data['lang'] = 'en';
     $data['skip_landing'] = 1;
     $data['id_type'] = 1;
     $data['merchant_order_id'] = $invoice->getId();
     // will be returned as vendor_order_id in IPN
     $data['card_holder_name'] = $full_name;
     $data['phone'] = $b->getPhone();
     $data['phone_extension'] = '';
     $data['email'] = $b->getEmail();
     $data['street_address'] = $b->getAddress();
     $data['city'] = $b->getCity();
     $data['state'] = $b->getState();
     $data['zip'] = $b->getZip();
     $data['country'] = $b->getCountry();
     $data['ship_name'] = $full_name;
     $data['ship_steet_address'] = $b->getAddress();
     $data['ship_city'] = $b->getCity();
     $data['ship_state'] = $b->getState();
     $data['ship_zip'] = $b->getZip();
     $data['ship_country'] = $b->getCountry();
     $data['cart_order_id'] = $invoice->getNumber();
     foreach ($invoice->getItems() as $i => $item) {
         $data['li_' . $i . '_type'] = 'product';
         $data['li_' . $i . '_tangible'] = 'N';
         $data['li_' . $i . '_product_id'] = $item->getId();
         $data['li_' . $i . '_name'] = $item->getTitle();
         $data['li_' . $i . '_quantity'] = $item->getQuantity();
         $data['li_' . $i . '_description'] = $item->getDescription();
         $data['li_' . $i . '_price'] = $item->getTotalWithTax();
     }
     if ($this->testMode) {
         $data['demo'] = 'Y';
     }
     return $data;
 }
Example #3
0
 public function singlePayment(Payment_Invoice $invoice)
 {
     $client = $invoice->getBuyer();
     $contract = $this->getParam('type');
     switch ($contract) {
         case '0':
             $service = 'trade_create_by_buyer';
             break;
         case '1':
             $service = 'create_direct_pay_by_user';
             break;
         case '2':
             $service = 'create_partner_trade_by_buyer';
             break;
     }
     $parameter = array('service' => $service, 'partner' => $this->getParam('partner'), '_input_charset' => $this->getParam('charset'), 'notify_url' => $this->getParam('notify_url'), 'return_url' => $this->getParam('thankyou_url'), 'subject' => $invoice->getTitle(), 'out_trade_no' => $invoice->getId(), 'price' => $invoice->getTotalWithTax(), 'quantity' => 1, 'payment_type' => 1, 'logistics_type' => 'EXPRESS', 'logistics_fee' => 0, 'logistics_payment' => 'BUYER_PAY_AFTER_RECEIVE', 'seller_email' => $this->getParam('seller_email'));
     ksort($parameter);
     reset($parameter);
     $data = $parameter;
     $data['sign'] = $this->_generateSignature($parameter);
     $data['sign_type'] = 'MD5';
     return $data;
 }
 public function recurrentPayment(Payment_Invoice $invoice)
 {
     $recurrenceInfo = $invoice->getSubscription();
     $amount = $invoice->getCurrency() . ' ' . $invoice->getTotalWithTax();
     $description = $invoice->getTitle();
     $promotionAmount = 0;
     $processImmediate = true;
     $immediateReturn = true;
     $referenceId = $invoice->getId();
     $recurringStartDate = "";
     $recurringFrequency = $this->_getRecurringFrequency($recurrenceInfo);
     // '1 month'
     $subscriptionPeriod = "";
     //'12 months';
     $formHiddenInputs['accessKey'] = $this->getParam('AWSAccessKeyId');
     $formHiddenInputs['amount'] = $amount;
     $formHiddenInputs['description'] = $description;
     $formHiddenInputs['recurringFrequency'] = $recurringFrequency;
     $formHiddenInputs['subscriptionPeriod'] = $subscriptionPeriod;
     $formHiddenInputs['recurringStartDate'] = $recurringStartDate;
     $formHiddenInputs['promotionAmount'] = $promotionAmount;
     $formHiddenInputs['referenceId'] = $referenceId;
     $formHiddenInputs['immediateReturn'] = true;
     $formHiddenInputs['ipnUrl'] = $this->getParam('notify_url');
     $formHiddenInputs['returnUrl'] = $this->getParam('return_url');
     $formHiddenInputs['abandonUrl'] = $this->getParam('cancel_url');
     $formHiddenInputs['processImmediate'] = $processImmediate;
     uksort($formHiddenInputs, "strnatcasecmp");
     $stringToSign = "";
     foreach ($formHiddenInputs as $formHiddenInputName => $formHiddenInputValue) {
         $stringToSign = $stringToSign . $formHiddenInputName . $formHiddenInputValue;
     }
     $formHiddenInputs['signature'] = $this->_getSignature($stringToSign);
     //throw new Exception(print_r($formHiddenInputs, 1));
     return $formHiddenInputs;
 }
Example #5
0
 public function isIpnValid($data, Payment_Invoice $invoice)
 {
     $ipn = $data['post'];
     if ($this->testMode && isset($ipn['x_test_request']) && $ipn['x_test_request'] == 'true') {
         return true;
     }
     $hash = $this->_getHash($ipn['x_trans_id'], $invoice->getTotalWithTax());
     return $ipn['x_MD5_Hash'] == $hash;
 }
Example #6
0
 /**
  * @param \Model_Invoice $invoice
  * @param bool $subscribe
  * @return \Payment_Invoice
  */
 public function getPaymentInvoice(\Model_Invoice $invoice, $subscribe = false)
 {
     $proforma = $this->toApiArray($invoice);
     $client = $this->getBuyer($invoice);
     $buyer = new \Payment_Invoice_Buyer();
     $buyer->setEmail($client['email'])->setFirstName($client['first_name'])->setLastName($client['last_name'])->setCompany($client['company'])->setAddress($client['address'])->setCity($client['city'])->setState($client['state'])->setZip($client['zip'])->setPhone($client['phone'])->setPhoneCountryCode($client['phone_cc'])->setCountry($client['country']);
     $first_title = null;
     $items = array();
     foreach ($proforma['lines'] as $item) {
         $pi = new \Payment_Invoice_Item();
         $pi->setId($item['id'])->setTitle($item['title'])->setDescription($item['title'])->setPrice($item['price'])->setTax($item['tax'])->setQuantity($item['quantity']);
         $items[] = $pi;
         if (is_null($first_title) && count($proforma['lines']) == 1) {
             $first_title = $item['title'];
         }
     }
     $params = array(':id' => sprintf('%05s', $proforma['nr']), ':serie' => $proforma['serie'], ':title' => $first_title);
     if ($first_title) {
         $title = __('Payment for invoice :serie:id [:title]', $params);
     } else {
         $title = __('Payment for invoice :serie:id', $params);
     }
     $mpi = new \Payment_Invoice();
     $mpi->setId($invoice->id);
     $mpi->setNumber($proforma['nr']);
     $mpi->setBuyer($buyer);
     $mpi->setCurrency($proforma['currency']);
     $mpi->setTitle($title);
     $mpi->setItems($items);
     $subscribeService = $this->di['mod_service']('Invoice', 'Subscription');
     // can subscribe only if proforma has one item with defined period
     if ($subscribe && $subscribeService->isSubscribable($invoice->id)) {
         $subitem = $invoice->InvoiceItem->getFirst();
         $period = $this->di['period']($subitem->period);
         $bs = new \Payment_Invoice_Subscription();
         $bs->setId($proforma['id']);
         $bs->setAmount($mpi->getTotalWithTax());
         $bs->setCycle($period->getQty());
         $bs->setUnit($period->getUnit());
         $mpi->setSubscription($bs);
         $mpi->setTitle('Subscription for ' . $subitem->title);
     }
     return $mpi;
 }
Example #7
0
 /**
  * Init single payment call to webservice
  * Invoice id is passed via notify_url
  *
  * @return string
  */
 public function singlePayment(Payment_Invoice $invoice)
 {
     $buyer = $invoice->getBuyer();
     return WebToPay::buildRequest(array('projectid' => $this->getParam('projectid'), 'sign_password' => $this->getParam('sign_password'), 'orderid' => $invoice->getNumber(), 'amount' => $this->moneyFormat($invoice->getTotalWithTax()), 'currency' => $invoice->getCurrency(), 'accepturl' => $this->getParam('return_url'), 'cancelurl' => $this->getParam('cancel_url'), 'callbackurl' => $this->getParam('notify_url'), 'paytext' => $invoice->getTitle(), 'p_firstname' => $buyer->getFirstName(), 'p_lastname' => $buyer->getLastName(), 'p_email' => $buyer->getEmail(), 'p_street' => $buyer->getAddress(), 'p_city' => $buyer->getCity(), 'p_state' => $buyer->getState(), 'p_zip' => $buyer->getZip(), 'p_countrycode' => $buyer->getCountry(), 'lang' => 'ENG', 'test' => $this->testMode));
 }
Example #8
0
 /**
  * Handle IPN and return response object
  * @return Payment_Transaction
  */
 public function getTransaction($data, Payment_Invoice $invoice)
 {
     $ipn = $data['post'];
     $client = $this->_getSoapClient();
     $Pay_Status = 'FAIL';
     $terminalId = $this->getParam('terminalId');
     $userName = $this->getParam('userName');
     $userPassword = $this->getParam('userPassword');
     $refId = $ipn['RefId'];
     $resCode = $ipn['ResCode'];
     $orderId = $ipn['SaleOrderId'];
     $verifySaleOrderId = $ipn['SaleOrderId'];
     $verifySaleReferenceId = $ipn['SaleReferenceId'];
     $parameters = array('terminalId' => $terminalId, 'userName' => $userName, 'userPassword' => $userPassword, 'orderId' => $orderId, 'saleOrderId' => $verifySaleOrderId, 'saleReferenceId' => $verifySaleReferenceId);
     error_log('Parameters: ' . print_r($parameters, 1));
     $result = $client->bpVerifyRequest($parameters);
     $VerifyAnswer = $result->return;
     error_log('Verify answer:' . $VerifyAnswer);
     if ($VerifyAnswer == '0') {
         // Call the SOAP method
         $result = $client->bpSettleRequest($parameters);
         $SetlleAnswer = $result->return;
         error_log('Settle answer:' . $SetlleAnswer);
         if ($SetlleAnswer == '0') {
             $Pay_Status = 'OK';
         }
     }
     if ($VerifyAnswer != '0' and $VerifyAnswer != '') {
         $result = $client->bpInquiryRequest($parameters);
         $InquiryAnswer = $result->return;
         error_log('Inquiry Answer:' . $InquiryAnswer);
         if ($InquiryAnswer == '0') {
             // Call the SOAP method
             $result = $client->bpSettleRequest($parameters);
             $SetlleAnswer = $result->return;
             error_log('Second Settle Answer:' . $InquiryAnswer);
             if ($SetlleAnswer == '0') {
                 $Pay_Status = 'OK';
             }
         } else {
             // Call the SOAP method
             $result = $client->bpReversalRequest($parameters);
             $ReversalAnswer = $result->return;
             error_log('Reversal request Answer:' . $ReversalAnswer);
         }
     }
     if ($Pay_Status != 'OK') {
         throw new Payment_Exception('Sale verification failed: ' . $VerifyAnswer);
     }
     $response = new Payment_Transaction();
     $response->setType(Payment_Transaction::TXTYPE_PAYMENT);
     $response->setId($refId);
     $response->setAmount($invoice->getTotalWithTax());
     $response->setCurrency($invoice->getCurrency());
     $response->setStatus(Payment_Transaction::STATUS_COMPLETE);
     return $response;
 }
 public function getTransaction($data, Payment_Invoice $invoice)
 {
     $ipn = $data['post'];
     //@todo
     $response = new Payment_Transaction();
     $response->setType(Payment_Transaction::TXTYPE_PAYMENT);
     $response->setId(uniqid());
     $response->setAmount($invoice->getTotalWithTax());
     $response->setCurrency($invoice->getCurrency());
     $response->setStatus(Payment_Transaction::STATUS_COMPLETE);
     return $response;
 }