/** * @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('&', '<', '>'); $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; }
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; }
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("&", "&", $shastring); $shastring = str_replace("<", "<", $shastring); $shastring = str_replace(">", "gt-teken", $shastring); $shastring = str_replace(""", "\"", $shastring); return sha1($shastring); }
/** * 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; }