Mage_AmazonPayments_Model_Api_Cba_Document Class Reference

Inheritance diagram for Mage_AmazonPayments_Model_Api_Cba_Document:

Varien_Object

List of all members.

Public Member Functions

 setWsdlUri ($wsdlUri)
 getWsdlUri ()
 setMerchantInfo (array $merchantInfo=array())
 getMerchantInfo ()
 getMerchantIdentifier ()
 getClient ()
 init ($login, $password)
 formatAmount ($amount)
 getDocument ($aOrderId)
 getPendingDocuments ()
 sendAcknowledgement ($order)
 cancel ($order)
 refund ($payment, $amount)
 confirmShipment ($aOrderId, $carrierName, $shippingMethod, $items, $trackNumber= '')
 sendTrackNumber ($order, $carrierCode, $carrierMethod, $trackNumber)

Public Attributes

const MESSAGE_TYPE_ADJUSTMENT = '_POST_PAYMENT_ADJUSTMENT_DATA_'
const MESSAGE_TYPE_FULFILLMENT = '_POST_ORDER_FULFILLMENT_DATA_'
const MESSAGE_TYPE_ACKNOWLEDGEMENT = '_POST_ORDER_ACKNOWLEDGEMENT_DATA_'

Protected Member Functions

 _construct ()
 _createAttachment ($document)
 _proccessRequest ($method, $params)

Protected Attributes

 $_wsdlUri = null
 $_merchantInfo = array()
 $_client = null
 $_result = null
 $_proccessFailed = false
 $_options


Detailed Description

Definition at line 35 of file Document.php.


Member Function Documentation

_construct (  )  [protected]

Enter description here...

Reimplemented from Varien_Object.

Definition at line 51 of file Document.php.

00052     {
00053         parent::_construct();
00054     }

_createAttachment ( document  )  [protected]

Create soap attachment (MIME encoding)

Parameters:
string $document
Returns:
string

Definition at line 154 of file Document.php.

00155     {
00156         require_once 'SOAP/Value.php';
00157         $attachment = new SOAP_Attachment('doc', 'application/binary', null, $document);
00158         $attachment->options['attachment']['encoding'] = '8bit';
00159         $this->_options['attachments'] = 'Mime';
00160         return $attachment;
00161     }

_proccessRequest ( method,
params 
) [protected]

Proccess request and setting result

Parameters:
string $method
array $params
Returns:
Mage_AmazonPayments_Model_Api_Cba_Document

Definition at line 170 of file Document.php.

00171     {
00172         if ($this->getClient()) {
00173             $this->_result = null;
00174             $this->_proccessFailed = false;
00175             try {
00176                 $this->_result = $this->getClient()
00177                     ->call($method, $params, $this->_options);
00178             } catch (Exception $e) {
00179                 $this->_proccessFailed = true;
00180             }
00181         }
00182         return $this;
00183     }

cancel ( order  ) 

Cancel order

Parameters:
Mage_Sales_Model_Order $order
Returns:
string Amazon Transaction Id

Definition at line 288 of file Document.php.

00289     {
00290         $_document = '<?xml version="1.0" encoding="UTF-8"?>
00291         <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
00292         <Header>
00293             <DocumentVersion>1.01</DocumentVersion>
00294             <MerchantIdentifier>' . $this->getMerchantIdentifier() . '</MerchantIdentifier>
00295         </Header>
00296         <MessageType>OrderAcknowledgement</MessageType>
00297             <Message>
00298                 <MessageID>1</MessageID>
00299                 <OperationType>Update</OperationType>
00300                 <OrderAcknowledgement>
00301                     <AmazonOrderID>' . $order->getExtOrderId() . '</AmazonOrderID>
00302                     <StatusCode>Failure</StatusCode>
00303                 </OrderAcknowledgement>
00304             </Message>
00305         </AmazonEnvelope>';
00306 
00307         $params = array(
00308             'merchant' => $this->getMerchantInfo(),
00309             'messageType' => self::MESSAGE_TYPE_ACKNOWLEDGEMENT,
00310             'doc' => $this->_createAttachment($_document)
00311         );
00312 
00313         $this->_proccessRequest('postDocument', $params);
00314         return $this->_result;
00315     }

confirmShipment ( aOrderId,
carrierName,
shippingMethod,
items,
trackNumber = '' 
)

Confirm creating of shipment

Parameters:
string $aOrderId
string $carrierName
string $shippingMethod
array $items
string $trackNumber
Returns:
string Amazon Transaction Id

Definition at line 398 of file Document.php.

00399     {
00400         $fulfillmentDate = gmdate('Y-m-d\TH:i:s');
00401         $_document = '<?xml version="1.0" encoding="UTF-8"?>
00402             <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
00403             <Header>
00404                 <DocumentVersion>1.01</DocumentVersion>
00405                 <MerchantIdentifier>' . $this->getMerchantIdentifier() . '</MerchantIdentifier>
00406             </Header>
00407             <MessageType>OrderFulfillment</MessageType>
00408             <Message>
00409                 <MessageID>1</MessageID>
00410                 <OrderFulfillment>
00411                     <AmazonOrderID>' . $aOrderId . '</AmazonOrderID>
00412                     <FulfillmentDate>' . $fulfillmentDate . '</FulfillmentDate>
00413                     <FulfillmentData>
00414                         <CarrierName>' . strtoupper($carrierName) . '</CarrierName>
00415                         <ShippingMethod>' . $shippingMethod . '</ShippingMethod>
00416                         <ShipperTrackingNumber>' . $trackNumber .'</ShipperTrackingNumber>
00417                     </FulfillmentData>';
00418         foreach ($items as $item) {
00419             $_document .= '<Item>
00420                             <AmazonOrderItemCode>' . $item['id'] . '</AmazonOrderItemCode>
00421                             <Quantity>' . $item['qty'] . '</Quantity>
00422                         </Item>';
00423         }
00424         $_document .= '</OrderFulfillment>
00425                 </Message>
00426         </AmazonEnvelope>';
00427         $params = array(
00428             'merchant' => $this->getMerchantInfo(),
00429             'messageType' => self::MESSAGE_TYPE_FULFILLMENT,
00430             'doc' => $this->_createAttachment($_document)
00431         );
00432         $this->_proccessRequest('postDocument', $params);
00433         return $this->_result;
00434     }

formatAmount ( amount  ) 

Format amount value (2 digits after the decimal point)

Parameters:
float $amount
Returns:
float

Definition at line 191 of file Document.php.

00192     {
00193         return Mage::helper('amazonpayments')->formatAmount($amount);
00194     }

getClient (  ) 

Return Soap object

Returns:
SOAP_Client

Definition at line 118 of file Document.php.

00119     {
00120         return $this->_client;
00121     }

getDocument ( aOrderId  ) 

Get order info

Parameters:
string $aOrderId Amazon order id
Returns:
Varien_Simplexml_Element

Definition at line 202 of file Document.php.

00203     {
00204         $params = array(
00205             'merchant' => $this->getMerchantInfo(),
00206             'documentIdentifier' => $aOrderId
00207         );
00208         $this->_proccessRequest('getDocument', $params);
00209 
00210         require_once 'Mail/mimeDecode.php';
00211         $decoder = new Mail_mimeDecode($this->getClient()->xml);
00212         $decoder->decode(array(
00213             'include_bodies' => true,
00214             'decode_bodies'  => true,
00215             'decode_headers' => true,
00216         ));
00217         $xml = $decoder->_body;
00218 
00219         // remove the ending mime boundary
00220         $boundaryIndex = strripos($xml, '--xxx-WASP-CPP-MIME-Boundary-xxx');
00221         if (!($boundaryIndex === false)) {
00222             $xml = substr($xml, 0, $boundaryIndex);
00223         }
00224 
00225         return simplexml_load_string($xml, 'Varien_Simplexml_Element');
00226     }

getMerchantIdentifier (  ) 

Return merchant identifier

Returns:
string

Definition at line 105 of file Document.php.

00106     {
00107         if (array_key_exists('merchantIdentifier', $this->_merchantInfo)) {
00108             return $this->_merchantInfo['merchantIdentifier'];
00109         }
00110         return null;
00111     }

getMerchantInfo (  ) 

Return merchant info

Returns:
array

Definition at line 95 of file Document.php.

00096     {
00097         return $this->_merchantInfo;
00098     }

getPendingDocuments (  ) 

Get pending orders

Returns:
array

Definition at line 233 of file Document.php.

00234     {
00235         $params = array(
00236             'merchant' => $this->getMerchantInfo(),
00237             'messageType' => '_GET_ORDERS_DATA_'
00238         );
00239         $this->_proccessRequest('getAllPendingDocumentInfo', $params);
00240         if (!is_array($this->_result)) {
00241             $this->_result = array($this->_result);
00242         }
00243         return $this->_result;
00244     }

getWsdlUri (  ) 

Return Wsdl Uri

Returns:
string

Definition at line 73 of file Document.php.

00074     {
00075         return $this->_wsdlUri;
00076     }

init ( login,
password 
)

Initialize Soap Client object and authorize

Parameters:
string $login
string $password
Returns:
Mage_AmazonPayments_Model_Api_Cba_Document

Definition at line 130 of file Document.php.

00131     {
00132         if ($this->getWsdlUri()) {
00133             $this->_client = null;
00134             $auth = array('user' => $login, 'pass' => $password);
00135             try {
00136                 set_include_path(
00137                      BP . DS . 'lib' . DS . 'PEAR' . PS . get_include_path()
00138                 );
00139                 require_once 'SOAP/Client.php';
00140                 $this->_client = new SOAP_Client($this->getWsdlUri(), true, false, $auth, false);
00141             } catch (Exception $e) {
00142                 Zend_Debug::dump($e->getMessage());
00143             }
00144         }
00145         return $this;
00146     }

refund ( payment,
amount 
)

Refund order

Parameters:
Mage_Sales_Model_Order_Payment $payment
float $amount
Returns:
string Amazon Transaction Id

Definition at line 324 of file Document.php.

00325     {
00326         $_document = '<?xml version="1.0" encoding="UTF-8"?>
00327             <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
00328             <Header>
00329                 <DocumentVersion>1.01</DocumentVersion>
00330                 <MerchantIdentifier>' . $this->getMerchantIdentifier() . '</MerchantIdentifier>
00331             </Header>
00332             <MessageType>OrderAdjustment</MessageType>';
00333 
00334         $_shippingAmount = $payment->getCreditmemo()->getShippingAmount();
00335         $_messageId = 1;
00336         foreach ($payment->getCreditmemo()->getAllItems() as $item) {
00337             /* @var $item Mage_Sales_Model_Order_Creditmemo_Item */
00338             if ($item->getOrderItem()->getParentItemId()) {
00339                 continue;
00340             }
00341 
00342             $shipping = 0;
00343             $amazon_amounts = unserialize($item->getOrderItem()->getProductOptionByCode('amazon_amounts'));
00344             if ($amazon_amounts['shipping'] > $_shippingAmount) {
00345                 $shipping = $_shippingAmount;
00346             } else {
00347                 $shipping = $amazon_amounts['shipping'];
00348             }
00349             $_shippingAmount -= $shipping;
00350 
00351             $_document .= '<Message>
00352                             <MessageID>' . $_messageId . '</MessageID>
00353                             <OrderAdjustment>
00354                                 <AmazonOrderID>' . $payment->getOrder()->getExtOrderId() . '</AmazonOrderID>
00355                                 <AdjustedItem>
00356                                     <AmazonOrderItemCode>'. $item->getOrderItem()->getExtOrderItemId() . '</AmazonOrderItemCode>
00357                                     <AdjustmentReason>GeneralAdjustment</AdjustmentReason>
00358                                     <ItemPriceAdjustments>
00359                                         <Component>
00360                                             <Type>Principal</Type>
00361                                             <Amount currency="USD">' . $this->formatAmount($item->getBaseRowTotal()) . '</Amount>
00362                                         </Component>
00363                                         <Component>
00364                                             <Type>Tax</Type>
00365                                             <Amount currency="USD">' . $this->formatAmount($item->getBaseTaxAmount()) . '</Amount>
00366                                         </Component>'
00367                                         .'<Component>
00368                                             <Type>Shipping</Type>
00369                                             <Amount currency="USD">' . $this->formatAmount($shipping) . '</Amount>
00370                                         </Component>'
00371                                     .'</ItemPriceAdjustments>';
00372             $_document .= '</AdjustedItem>
00373                         </OrderAdjustment>
00374                     </Message>';
00375             $_messageId++;
00376         }
00377 
00378         $_document .= '</AmazonEnvelope>';
00379         $params = array(
00380             'merchant' => $this->getMerchantInfo(),
00381             'messageType' => self::MESSAGE_TYPE_ADJUSTMENT,
00382             'doc' => $this->_createAttachment($_document)
00383         );
00384         $this->_proccessRequest('postDocument', $params);
00385         return $this->_result;
00386     }

sendAcknowledgement ( order  ) 

Associate Magento real order id with Amazon order id

Parameters:
Mage_Sales_Model_Order $order
Returns:
string

Definition at line 252 of file Document.php.

00253     {
00254         $_document = '<?xml version="1.0" encoding="UTF-8"?>
00255         <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
00256         <Header>
00257             <DocumentVersion>1.01</DocumentVersion>
00258             <MerchantIdentifier>' . $this->getMerchantIdentifier() . '</MerchantIdentifier>
00259         </Header>
00260         <MessageType>OrderAcknowledgement</MessageType>
00261             <Message>
00262                 <MessageID>1</MessageID>
00263                 <OperationType>Update</OperationType>
00264                 <OrderAcknowledgement>
00265                     <AmazonOrderID>' . $order->getExtOrderId() . '</AmazonOrderID>
00266                     <MerchantOrderID>' . $order->getRealOrderId() . '</MerchantOrderID>
00267                     <StatusCode>Success</StatusCode>
00268                 </OrderAcknowledgement>
00269             </Message>
00270         </AmazonEnvelope>';
00271 
00272         $params = array(
00273             'merchant' => $this->getMerchantInfo(),
00274             'messageType' => self::MESSAGE_TYPE_ACKNOWLEDGEMENT,
00275             'doc' => $this->_createAttachment($_document)
00276         );
00277 
00278         $this->_proccessRequest('postDocument', $params);
00279         return $this->_result;
00280     }

sendTrackNumber ( order,
carrierCode,
carrierMethod,
trackNumber 
)

Send Tracking Number

Parameters:
Mage_Sales_Model_Order $order
string $carrierCode
string $carrierMethod
string $trackNumber
Returns:
string Amazon Transaction Id

Definition at line 445 of file Document.php.

00446     {
00447         $fulfillmentDate = gmdate('Y-m-d\TH:i:s');
00448         $_document = '<?xml version="1.0" encoding="UTF-8"?>
00449             <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
00450             <Header>
00451                 <DocumentVersion>1.01</DocumentVersion>
00452                 <MerchantIdentifier>' . $this->getMerchantIdentifier() . '</MerchantIdentifier>
00453             </Header>
00454             <MessageType>OrderFulfillment</MessageType>';
00455             $_document .= '<Message>
00456                     <MessageID>1</MessageID>
00457                     <OrderFulfillment>
00458                         <AmazonOrderID>' . $order->getExtOrderId() . '</AmazonOrderID>
00459                         <FulfillmentDate>' . $fulfillmentDate . '</FulfillmentDate>
00460                         <FulfillmentData>
00461                             <CarrierCode>' . $carrierCode . '</CarrierCode>
00462                             <ShippingMethod>' . $carrierMethod . '</ShippingMethod>
00463                             <ShipperTrackingNumber>' . $trackNumber .'</ShipperTrackingNumber>
00464                         </FulfillmentData>
00465                     </OrderFulfillment>
00466                 </Message>';
00467         $_document .= '</AmazonEnvelope>';
00468         $params = array(
00469             'merchant' => $this->getMerchantInfo(),
00470             'messageType' => self::MESSAGE_TYPE_FULFILLMENT,
00471             'doc' => $this->_createAttachment($_document)
00472         );
00473         $this->_proccessRequest('postDocument', $params);
00474         return $this->_result;
00475     }

setMerchantInfo ( array merchantInfo = array()  ) 

Set merchant info

Parameters:
array $merchantInfo
Returns:
Mage_AmazonPayments_Model_Api_Cba_Document

Definition at line 84 of file Document.php.

00085     {
00086         $this->_merchantInfo = $merchantInfo;
00087         return $this;
00088     }

setWsdlUri ( wsdlUri  ) 

Set Wsdl uri

Parameters:
string $wsdlUri
Returns:
Mage_AmazonPayments_Model_Api_Cba_Document

Definition at line 62 of file Document.php.

00063     {
00064         $this->_wsdlUri = $wsdlUri;
00065         return $this;
00066     }


Member Data Documentation

$_client = null [protected]

Definition at line 43 of file Document.php.

$_merchantInfo = array() [protected]

Definition at line 42 of file Document.php.

$_options [protected]

Initial value:

 array(
        'trace'     => true,
        'timeout'   => '20',
    )

Definition at line 46 of file Document.php.

$_proccessFailed = false [protected]

Definition at line 45 of file Document.php.

$_result = null [protected]

Definition at line 44 of file Document.php.

$_wsdlUri = null [protected]

Definition at line 41 of file Document.php.

const MESSAGE_TYPE_ACKNOWLEDGEMENT = '_POST_ORDER_ACKNOWLEDGEMENT_DATA_'

Definition at line 39 of file Document.php.

const MESSAGE_TYPE_ADJUSTMENT = '_POST_PAYMENT_ADJUSTMENT_DATA_'

Definition at line 37 of file Document.php.

const MESSAGE_TYPE_FULFILLMENT = '_POST_ORDER_FULFILLMENT_DATA_'

Definition at line 38 of file Document.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:31 2009 for Magento by  doxygen 1.5.8