Class: ActiveMerchant::Shipping::Stamps

Inherits:
Carrier show all
Defined in:
lib/active_shipping/shipping/carriers/stamps.rb

Overview

Stamps.com integration for rating, tracking, address validation, and label generation Integration ID can be requested from Stamps.com

Constant Summary collapse

LIVE_URL =

TODO: Update to latest API. Documentation for the latest WSDL version is available here: support.stamps.com/outgoing/swsimv39doc.zip

'https://swsim.stamps.com/swsim/swsimv34.asmx'
TEST_URL =
'https://swsim.testing.stamps.com/swsim/swsimv34.asmx'
NAMESPACE =
'http://stamps.com/xml/namespace/2014/01/swsim/swsimv34'
REQUIRED_OPTIONS =
[:integration_id, :username, :password].freeze
PACKAGE =
[
  'Postcard',
  'Letter',
  'Large Envelope or Flat',
  'Thick Envelope',
  'Package',
  'Flat Rate Box',
  'Small Flat Rate Box',
  'Large Flat Rate Box',
  'Flat Rate Envelope',
  'Flat Rate Padded Envelope',
  'Large Package',
  'Oversized Package',
  'Regional Rate Box A',
  'Regional Rate Box B',
  'Regional Rate Box C',
  'Legal Flat Rate Envelope'
].freeze
US_POSSESSIONS =
%w(AS FM GU MH MP PW PR VI)
SERVICE_TYPES =
{
  'US-FC'  => 'USPS First-Class Mail',
  'US-MM'  => 'USPS Media Mail',
  'US-PM'  => 'USPS Priority Mail',
  'US-BP'  => 'USPS BP',
  'US-LM'  => 'USPS LM',
  'US-XM'  => 'USPS Express Mail',
  'US-EMI' => 'USPS Express Mail International',
  'US-PMI' => 'USPS Priority Mail International',
  'US-FCI' => 'USPS First Class Mail International',
  'US-CM'  => 'USPS Critical Mail',
  'US-PS'  => 'USPS Parcel Select'
}
ADD_ONS =
{
  'SC-A-HP'    => 'Hidden Postage',
  'SC-A-INS'   => 'Insurance',
  'SC-A-INSRM' => 'Insurance for Registered Mail',
  'US-A-CM'    => 'Certified Mail',
  'US-A-COD'   => 'Collect on Delivery',
  'US-A-COM'   => 'Certificate of Mailing',
  'US-A-DC'    => 'USPS Delivery Confirmation',
  'US-A-ESH'   => 'USPS Express - Sunday / Holiday Guaranteed',
  'US-A-INS'   => 'USPS Insurance',
  'US-A-NDW'   => 'USPS Express - No Delivery on Saturdays',
  'US-A-RD'    => 'Restricted Delivery',
  'US-A-REG'   => 'Registered Mail',
  'US-A-RR'    => 'Return Receipt Requested',
  'US-A-RRM'   => 'Return Receipt for Merchandise',
  'US-A-SC'    => 'USPS Signature Confirmation',
  'US-A-SH'    => 'Special Handling',
  'US-A-NND'   => 'Notice of non-delivery',
  'US-A-SR'    => 'Unknow Service Name SR',
  'US-A-RRE'   => 'Unknow Service Name RRE'
}
CARRIER_PICKUP_LOCATION =
{
  'FrontDoor'             => 'Packages are at front door',
  'BackDoor'              => 'Packages are at back door',
  'SideDoor'              => 'Packages are at side door',
  'KnockOnDoorOrRingBell' => 'Knock on door or ring bell',
  'MailRoom'              => 'Packages are in mail room',
  'Office'                => 'Packages are in office',
  'Reception'             => 'Packages are at reception area',
  'InOrAtMailbox'         => 'Packages are in mail box',
  'Other'                 => 'Other Location'
}
[
  'Normal',
  'NormalLeft',
  'NormalRight',
  'Normal4X6',
  'Normal6X4',
  'Normal75X2',
  'NormalReceipt',
  'NormalCN22',
  'NormalCP72',
  'Normal4X6CN22',
  'Normal6X4CN22',
  'Normal4X6CP72',
  'Normal6X4CP72',
  'Normal4X675',
  'Normal4X675CN22',
  'Normal4X675CP72',
  'Return',
  'ReturnCN22',
  'ReturnCP72',
  'Return4X675',
  'Return4X675CN22',
  'Return4X675CP72',
  'SDC3510',
  'SDC3520',
  'SDC3530',
  'SDC3610',
  'SDC3710',
  'SDC3810',
  'SDC3820',
  'SDC3910',
  'Envelope9',
  'Envelope10',
  'Envelope11',
  'Envelope12',
  'EnvelopePersonal',
  'EnvelopeMonarch',
  'EnvelopeInvitation',
  'EnvelopeGreeting'
]
IMAGE_TYPE =
%w(Auto Epl Gif Jpg Pdf Png Zpl)
@@name =
'Stamps'

Instance Attribute Summary collapse

Attributes inherited from Carrier

#last_request, #test_mode

Instance Method Summary collapse

Methods inherited from Carrier

#initialize, #maximum_weight, #valid_credentials?

Constructor Details

This class inherits a constructor from ActiveMerchant::Shipping::Carrier

Instance Attribute Details

#last_swsim_methodObject (readonly)

Returns the value of attribute last_swsim_method


15
16
17
# File 'lib/active_shipping/shipping/carriers/stamps.rb', line 15

def last_swsim_method
  @last_swsim_method
end

Instance Method Details

#account_infoObject


136
137
138
139
# File 'lib/active_shipping/shipping/carriers/stamps.rb', line 136

def 
  request = 
  commit(:GetAccountInfo, request)
end

#clear_authenticatorObject


180
181
182
# File 'lib/active_shipping/shipping/carriers/stamps.rb', line 180

def clear_authenticator
  @authenticator = nil
end

#create_shipment(origin, destination, package, line_items = [], options = {}) ⇒ Object


164
165
166
167
168
169
# File 'lib/active_shipping/shipping/carriers/stamps.rb', line 164

def create_shipment(origin, destination, package, line_items = [], options = {})
  origin = standardize_address(origin)
  destination = standardize_address(destination)
  request = build_create_indicium_request(origin, destination, package, line_items, options)
  commit(:CreateIndicium, request)
end

#find_rates(origin, destination, package, options = {}) ⇒ Object


157
158
159
160
161
162
# File 'lib/active_shipping/shipping/carriers/stamps.rb', line 157

def find_rates(origin, destination, package, options = {})
  origin = standardize_address(origin)
  destination = standardize_address(destination)
  request = build_rate_request(origin, destination, package, options)
  commit(:GetRates, request)
end

#find_tracking_info(shipment_id, options = {}) ⇒ Object


171
172
173
174
# File 'lib/active_shipping/shipping/carriers/stamps.rb', line 171

def find_tracking_info(shipment_id, options = {})
  request = build_track_shipment_request(shipment_id, options)
  commit(:TrackShipment, request)
end

#namespaceObject


176
177
178
# File 'lib/active_shipping/shipping/carriers/stamps.rb', line 176

def namespace
  NAMESPACE
end

#purchase_postage(purchase_amount, control_total) ⇒ Object


141
142
143
144
# File 'lib/active_shipping/shipping/carriers/stamps.rb', line 141

def purchase_postage(purchase_amount, control_total)
  request = build_purchase_postage_request(purchase_amount, control_total)
  commit(:PurchasePostage, request)
end

#purchase_status(transaction_id) ⇒ Object


146
147
148
149
# File 'lib/active_shipping/shipping/carriers/stamps.rb', line 146

def purchase_status(transaction_id)
  request = build_get_purchase_status(transaction_id)
  commit(:GetPurchaseStatus, request)
end

#validate_address(address, options = {}) ⇒ Object


151
152
153
154
155
# File 'lib/active_shipping/shipping/carriers/stamps.rb', line 151

def validate_address(address, options = {})
  address = standardize_address(address)
  request = build_cleanse_address_request(address)
  commit(:CleanseAddress, request)
end