Exemple #1
0
 public function ipn($data, Payment_Invoice $invoice)
 {
     $tx = new Payment_Transaction();
     $tx->setAmount($invoice->getTotal());
     $tx->setCurrency($invoice->getCurrency());
     $tx->setId(md5(uniqid($invoice->getNumber())));
     $tx->setIsValid(true);
     $tx->setStatus(Payment_Transaction::STATUS_COMPLETE);
     $tx->setType(Payment_Transaction::TXTYPE_PAYMENT);
     return $tx;
 }
 /**
  * @see http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Tag_Reference.html
  */
 public function singlePayment(Payment_Invoice $invoice)
 {
     //replace in text nodes
     $what = array('&', '<', '>');
     $to = array('&#x26;', '&#x3c;', '&#x3e;');
     $xml = new DOMDocument('1.0', 'UTF-8');
     $root = $xml->createElement('checkout-shopping-cart');
     $root->setAttribute('xmlns', 'http://checkout.google.com/schema/2');
     $xml->appendChild($root);
     $shoppingCart = $xml->createElement('shopping-cart');
     $root->appendChild($shoppingCart);
     $items = $xml->createElement('items');
     $shoppingCart->appendChild($items);
     foreach ($invoice->getItems() as $i) {
         $item = $xml->createElement('item');
         $itemName = $xml->createElement('item-name', str_replace($what, $to, $i->getTitle()));
         $itemDescription = $xml->createElement('item-description', str_replace($what, $to, $i->getDescription()));
         $unitPrice = $xml->createElement('unit-price', $i->getPrice());
         $unitPrice->setAttribute('currency', $invoice->getCurrency());
         $quantity = $xml->createElement('quantity', $i->getQuantity());
         $digitalContent = $xml->createElement('digital-content');
         $description = $xml->createElement('description', str_replace($what, $to, '<a href="' . $this->getParam('return_url') . '">Click here to return to site</a>'));
         $digitalContent->appendChild($description);
         $item->appendChild($itemName);
         $item->appendChild($itemDescription);
         $item->appendChild($unitPrice);
         $item->appendChild($quantity);
         $item->appendChild($digitalContent);
         $items->appendChild($item);
     }
     $checkoutFlowSupport = $xml->createElement('checkout-flow-support');
     $root->appendChild($checkoutFlowSupport);
     $merchantCheckoutSupport = $xml->createElement('merchant-checkout-flow-support');
     $checkoutFlowSupport->appendChild($merchantCheckoutSupport);
     $continueShoppingUrl = $xml->createElement('continue-shopping-url', str_replace($what, $to, $this->getParam('continue_shopping_url')));
     $merchantCheckoutSupport->appendChild($continueShoppingUrl);
     $merchantPrivateDdata = $xml->createElement('merchant-private-data');
     $shoppingCart->appendChild($merchantPrivateDdata);
     $invoiceId = $xml->createElement('invoice', $invoice->getNumber());
     $merchantPrivateDdata->appendChild($invoiceId);
     $str = $xml->saveXML();
     $response = $this->_makeRequest($str);
     if (isset($response->{'redirect-url'})) {
         return urldecode($response->{'redirect-url'});
     } else {
         throw new Payment_Exception('Connection to Google Checkout servers failed');
     }
     return false;
 }
Exemple #3
0
 public function getTransaction($data, Payment_Invoice $invoice)
 {
     $ipn = $data['post'];
     $uniqid = md5($ipn['trade_no'] . $ipn['trade_status']);
     $tx = new Payment_Transaction();
     $tx->setId($uniqid);
     $tx->setAmount($ipn['total_fee']);
     $tx->setCurrency($invoice->getCurrency());
     $contract = $this->getParam('type');
     if ($contract == '1') {
         switch ($ipn['trade_status']) {
             case 'TRADE_SUCCESS':
             case 'TRADE_FINISHED':
                 $tx->setType(Payment_Transaction::TXTYPE_PAYMENT);
                 $tx->setStatus(Payment_Transaction::STATUS_COMPLETE);
                 break;
             default:
                 $tx->setStatus($ipn['trade_status']);
                 break;
         }
     }
     if ($contract == '2') {
         switch ($ipn['trade_status']) {
             case 'WAIT_SELLER_SEND_GOODS':
                 $tx->setType(Payment_Transaction::TXTYPE_PAYMENT);
                 $tx->setStatus(Payment_Transaction::STATUS_COMPLETE);
                 break;
             default:
                 $tx->setStatus($ipn['trade_status']);
                 break;
         }
     }
     return $tx;
 }
 private function _getHash(Payment_Invoice $invoice)
 {
     $shastring = $this->getParam('hashKey') . $this->getParam('merchantId') . $this->getParam('subId') . $invoice->getNumber() . 'ideal' . $this->_getValidUntil();
     $i = 1;
     foreach ($invoice->getItems() as $item) {
         $shastring .= $i . $item->getDescription() . $item->getQuantity() . (int) ($item->getPrice() * 100);
         $i++;
     }
     //Replace forbidden chars
     $shastring = str_replace(" ", "", $shastring);
     $shastring = str_replace("\t", "", $shastring);
     $shastring = str_replace("\n", "", $shastring);
     $shastring = str_replace("&amp;", "&", $shastring);
     $shastring = str_replace("&lt;", "<", $shastring);
     $shastring = str_replace("&gt;", "gt-teken", $shastring);
     $shastring = str_replace("&quot;", "\"", $shastring);
     return sha1($shastring);
 }
Exemple #5
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;
 }
Exemple #6
0
 public function singlePayment(Payment_Invoice $invoice)
 {
     $c = $invoice->getBuyer();
     $params = array('ap_merchant' => $this->getParam('email'), 'ap_purchasetype' => 'service', 'ap_currency' => $invoice->getCurrency(), 'ap_alerturl' => $this->getParam('notify_url'), 'ap_returnurl' => $this->getParam('return_url'), 'ap_cancelurl' => $this->getParam('cancel_url'), 'ap_fname' => $c->getFirstName(), 'ap_lname' => $c->getLastName(), 'ap_contactemail' => $c->getEmail(), 'ap_contactphone' => $c->getPhone(), 'ap_addressline1' => $c->getAddress(), 'ap_city' => $c->getCity(), 'ap_stateprovince' => $c->getState(), 'ap_zippostalcode' => $c->getZip(), 'ap_country' => $c->getCountry(), 'apc_1' => $invoice->getId(), 'apc_2' => $invoice->getNumber());
     $i = 1;
     foreach ($invoice->getItems() as $item) {
         $params['ap_itemcode_' . $i] = $item->getId();
         $params['ap_itemname_' . $i] = $item->getTitle();
         $params['ap_description_' . $i] = $item->getDescription();
         $params['ap_amount_' . $i] = $item->getPrice() + $item->getTax();
         $params['ap_quantity_' . $i] = $item->getQuantity();
         $i++;
     }
     return $params;
 }
 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;
 }
 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;
 }
Exemple #9
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));
 }
Exemple #10
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;
 }
 /**
  * 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;
 }
 /**
  * Init single payment call to webservice
  * Invoice id is passed via notify_url
  *
  * @param Payment_Invoice $invoice
  * @return array
  */
 public function singlePayment(Payment_Invoice $invoice)
 {
     return array('ik_co_id' => $this->getParam('ik_co_id'), 'ik_pm_no' => $invoice->getId(), 'ik_am' => $invoice->getTotal(), 'ik_desc' => $invoice->getTitle(), 'ik_cur' => $invoice->getCurrency(), 'ik_ia_u' => $this->getParam('notify_url'), 'ik_ia_m' => 'post', 'ik_suc_u' => $this->getParam('return_url'), 'ik_suc_m' => 'get', 'ik_pnd_u' => $this->getParam('return_url'), 'ik_pnd_m' => 'get', 'ik_fal_u' => $this->getParam('cancel_url'), 'ik_fal_m' => 'get', 'ik_x_iid' => $invoice->getId());
 }
 public function getTransaction($data, Payment_Invoice $invoice)
 {
     $ipn = $data['post'];
     $tx = new Payment_Transaction();
     $tx->setId($ipn['sign']);
     $tx->setAmount($ipn['total_fee']);
     $tx->setCurrency($invoice->getCurrency());
     $tx->setType(Payment_Transaction::TXTYPE_PAYMENT);
     switch ($ipn['trade_status']) {
         case 'TRADE_SUCCESS':
         case 'TRADE_FINISHED':
             //case 'WAIT_SELLER_SEND_GOODS':
             $tx->setStatus(Payment_Transaction::STATUS_COMPLETE);
             break;
         default:
             throw new Payment_Exception('Unknown AliPay IPN status :' . $ipn['trade_status']);
             break;
     }
     return $tx;
 }
 /**
  * Perform recurent payment
  * @param Payment_Invoice $invoice
  * @see http://www.2checkout.com/blog/knowledge-base/merchants/tech-support/3rd-party-carts/parameter-sets/pass-through-product-parameter-set/
  */
 public function recurrentPayment(Payment_Invoice $invoice)
 {
     $subs = $invoice->getSubscription();
     $buyer = $invoice->getBuyer();
     $data['sid'] = $this->getParam('vendor_nr');
     $data['mode'] = '2CO';
     foreach ($invoice->getItems() as $i => $item) {
         $data['li_' . $i . '_type'] = 'product';
         $data['li_' . $i . '_name'] = $item->getTitle();
         $data['li_' . $i . '_quantity'] = $item->getQuantity();
         $data['li_' . $i . '_tangible'] = 'N';
         $data['li_' . $i . '_description'] = $item->getDescription();
         $data['li_' . $i . '_recurrence'] = $subs->getCycle() . ' ' . ucfirst($subs->getUnit());
         $data['li_' . $i . '_price'] = $item->getTotalWithTax();
     }
     $data['merchant_order_id'] = $invoice->getId();
     $data['invoice_hash'] = $invoice->getId();
     $data['invoice_id'] = $invoice->getId();
     $data['fixed'] = 1;
     $data['lang'] = 'en';
     $data['skip_landing'] = 0;
     $data['id_type'] = 1;
     $data['x_receipt_link_URL'] = $this->getParam('return_url');
     $data['card_holder_name'] = $buyer->getFirstName() . ' ' . $buyer->getLastName();
     $data['phone'] = $buyer->getPhone();
     $data['phone_extension'] = '';
     $data['email'] = $buyer->getEmail();
     $data['street_address'] = $buyer->getAddress();
     $data['city'] = $buyer->getCity();
     $data['state'] = $buyer->getState();
     $data['zip'] = $buyer->getZip();
     $data['country'] = $buyer->getCountry();
     $data['subscription'] = 1;
     if ($this->testMode) {
         $data['demo'] = 'Y';
     }
     return $data;
 }
 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;
 }
 public function singlePayment(Payment_Invoice $invoice)
 {
     $c = $invoice->getBuyer();
     $params = array('pay_to_email' => $this->getParam('email'), 'transaction_id' => $invoice->getNumber(), 'return_url' => $this->getParam('return_url'), 'cancel_url' => $this->getParam('cancel_url'), 'status_url' => $this->getParam('notify_url'), 'merchant_fields' => 'invoice_id', 'invoice_id' => $invoice->getNumber(), 'pay_from_email' => $c->getEmail(), 'firstname' => $c->getFirstname(), 'lastname' => $c->getLastname(), 'address' => $c->getAddress(), 'phone_number' => $c->getPhone(), 'postal_code' => $c->getZip(), 'city' => $c->getCity(), 'state' => $c->getState(), 'country' => $c->getCountry(), 'amount' => $invoice->getTotal(), 'currency' => $invoice->getCurrency());
     return $params;
 }
 /**
  * @see http://www.libertyreserve.com/en/help/sciguide
  * @param Payment_Invoice $invoice
  * @return array - list of parameters to be posted to serviceUrl via POST method
  */
 public function singlePayment(Payment_Invoice $invoice)
 {
     $params = array('lr_acc' => $this->getParam('accountNumber'), 'lr_amnt' => $invoice->getTotal(), 'lr_currency' => 'LR' . $invoice->getCurrency(), 'lr_merchant_ref' => $invoice->getNumber(), 'lr_success_url' => $this->getParam('return_url'), 'lr_success_url_method' => 'GET', 'lr_fail_url' => $this->getParam('cancel_url'), 'lr_fail_url_method' => 'GET', 'lr_status_url' => $this->getParam('notify_url'), 'lr_status_url_method' => 'POST', 'lr_comments' => $invoice->getTitle(), 'bb_invoice_id' => $invoice->getId());
     return $params;
 }