def do_test(self): import logging logging.getLogger().setLevel(logging.DEBUG) endicia = Endicia(**settings.ENDICIA_CONF) endicia.format_xml = True print 'Querying label...' res = endicia.get_postage_label( weight=7, image_format=ImageFormat.GIF, mail_class=MailClass.First, mailpiece_shape=MailpieceShape.Parcel, stealth=False, rubber_stamp='CUSTOMER ID: 00000ABC\nORDER # 0000EFGH', services={ 'delivery_confirmation': False, }, reference_id='Store', description='Buy Shipping Label', partner_customer_id='00000ABC', partner_transaction_id='0000EFGH', to={ 'name': 'MARY WALZ', 'company': 'ENDICIA', 'address1': '247 HIGH ST', 'city': 'PALO ALTO', 'state': 'CA', 'postal_code': '94301', 'zip4': '0000', 'delivery_point': '00', 'country': 'United States', }, return_address='PO BOX 6487', frm={ 'name': 'GAMEMINE', 'city': 'DELRAY BEACH', 'state': 'FL', 'postal_code': '33482', 'zip4': '9901', }, postage_price=True) print ' PIC:', res.PIC print 'Checking status...' res = endicia.status_request(res.PIC, '9122148008600123456781') if isinstance(res.StatusList, list): for i in res.StatusList: i = i.PICNumber print ' %s: %s (%s)' % (i.PICNumber, i.StatusCode, i.Status) else: i = res.StatusList.PICNumber print ' %s: %s (%s)' % (i.PICNumber, i.StatusCode, i.Status) print 'DONE'
def request_mail_label(self): if self.mail_label: return True, None endicia = Endicia(**settings.ENDICIA_CONF) res = endicia.get_postage_label( weight=self.get_weight(), image_format=ImageFormat.GIF, mail_class=MailClass.First if self.get_weight() <= decimal.Decimal('7.0') else MailClass.MediaMail, mailpiece_shape=MailpieceShape.Parcel, stealth=False, rubber_stamp='CUSTOMER ID: %08d\nORDER # %08d' % (self.order.user.id, self.order.id), services={ 'delivery_confirmation': False, }, reference_id='Store', description='Buy Shipping Label', partner_customer_id='%08d' % self.order.user.id, partner_transaction_id='%08d' % self.id, to={ 'name': ' '.join((self.order.first_name, self.order.last_name)), 'address1': self.order.shipping_address1, 'address2': self.order.shipping_address2, 'city': self.order.shipping_city, 'state': self.order.shipping_state, 'postal_code': split_zip(self.order.shipping_zip_code)[0], 'zip4': split_zip(self.order.shipping_zip_code)[1], 'delivery_point': '00', }, frm={ 'name': 'GAMEMINE', 'city': self.source_dc.city.upper(), 'state': self.source_dc.state.upper(), 'postal_code': self.source_dc.postal_code.upper(), 'zip4': split_zip(self.source_dc.postal_code)[1].upper(), }, return_address=self.source_dc.address.upper(), postage_price=True) logger.debug('Mail label requested? %s', 'YES' if res.Status == '0' else 'NO') logger.debug('Status: %s (%s)', res.Status, res.ErrorMessage if res.Status != '0' else 'OK') if res.Status == '0': self.endicia_data = res._dict['LabelRequestResponse'] self.tracking_number = res.TrackingNumber label_file = ContentFile(base64.decodestring(res.Base64LabelImage)) # if self.mail_label: # self.mail_label.delete(False) self.mail_label.save('%08d.gif' % self.id, label_file) else: self.endicia_data = '' self.tracking_number = None # self.mail_label.delete(True) return res.Status == '0', res.ErrorMessage if res.Status != '0' else 'OK'
def do_recredit(self): endicia = Endicia(**settings.ENDICIA_CONF) endicia.format_xml = True res = endicia.get_account_status() #print res._xml balance = decimal.Decimal(res.CertifiedIntermediary.PostageBalance) debug('Current balance: %s', balance) if balance > 100 and balance < 1000000: return debug('Adding 300.0') res = endicia.recredit(300) #print res._xml balance = decimal.Decimal(res.CertifiedIntermediary.PostageBalance) debug('Current balance: %s', balance)
def do_get_balance(self): endicia = Endicia(**settings.ENDICIA_CONF) endicia.format_xml = True res = endicia.get_account_status() print res._xml
def setUp(self): self.endicia = Endicia(None, None, None, test_mode=True)
class EndiciaTests(TestCase): def setUp(self): self.endicia = Endicia(None, None, None, test_mode=True) def test_get_postage_label(self): # Outgoing mail label reply_postage = False description = "Rental Mailing Shipping Label" res_outgoing = self.endicia.get_postage_label( type=LabelType.DestinationConfirm, size=LabelSize.Dymo30384, image_format=ImageFormat.GIF, mail_class=MailClass.First, date_advance=7, weight=3.5, mailpiece_shape=MailpieceShape.Letter, machinable=True, sort_type=SortType.SinglePiece, include_postage=True, show_return_address=False, reply_postage=reply_postage, stealth=False, signature_waiver=True, no_weekend_delivery=False, no_holiday_delivery=True, return_to_sender=True, barcode_format="PLATNET Code, 14", cost_center=1, description=description, reference_id="Rent", partner_customer_id="12345678", partner_transaction_id="87654321", to={ "name": "Test Name", "address1": "1 Test St", "address2": "", "city": "Test City", "state": "Test State", "postal_code": "05105-123", "zip4": "1234", "delivery_point": "00", }, frm={ "city": u"DELRAY BEACH", "name": "GAMEMINE", "postal_code": u"33482-9901", "state": u"FL", "zip4": u"9901" }, return_address="PO BOX 6487", postage_price=True) self.assertTrue(res_outgoing.Base64LabelImage) # Incoming mail label reply_postage = True res_incoming = self.endicia.get_postage_label( type=LabelType.DestinationConfirm, size=LabelSize.Dymo30384, image_format=ImageFormat.GIF, mail_class=MailClass.First, date_advance=7, weight=3.5, mailpiece_shape=MailpieceShape.Letter, machinable=True, sort_type=SortType.SinglePiece, include_postage=True, show_return_address=False, reply_postage=reply_postage, stealth=False, signature_waiver=True, no_weekend_delivery=False, no_holiday_delivery=True, return_to_sender=True, barcode_format="PLATNET Code, 14", cost_center=1, description=description, reference_id="Rent", partner_customer_id="12345678", partner_transaction_id="87654321", to={ "name": "Test Name", "address1": "1 Test St", "address2": "", "city": "Test City", "state": "Test State", "postal_code": "05105-123", "zip4": "1234", "delivery_point": "00", }, frm={ "city": u"DELRAY BEACH", "name": "GAMEMINE", "postal_code": u"33482-9901", "state": u"FL", "zip4": u"9901" }, return_address="PO BOX 6487", postage_price=True) self.assertNotEqual(res_incoming.Base64LabelImage, res_outgoing.Base64LabelImage) def test_status_request(self): resp = self.endicia.status_request(12345) self.assertEqual(resp.StatusList.PICNumber.PICNumber, 12345) resp = self.endicia.status_request(12345, 54321) self.assertEqual(resp.StatusList[0].PICNumber, 12345) self.assertEqual(resp.StatusList[1].PICNumber, 54321) self.endicia.test_status_response = "D" resp = self.endicia.status_request(12345) self.assertEqual(resp.StatusList.PICNumber.StatusCode, "D")