forked from JeremyDunn/php-fedex-api-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddress-validation.php
More file actions
71 lines (56 loc) · 2.26 KB
/
address-validation.php
File metadata and controls
71 lines (56 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* This test will send the same test data as in FedEx's documentation:
* /php/RateAvailableServices/RateAvailableServices.php5
*/
//remember to copy example.credentials.php as credentials.php replace 'FEDEX_KEY', 'FEDEX_PASSWORD', 'FEDEX_ACCOUNT_NUMBER', and 'FEDEX_METER_NUMBER'
require_once 'credentials.php';
require_once 'bootstrap.php';
use FedEx\AddressValidationService;
use FedEx\AddressValidationService\ComplexType;
use FedEx\AddressValidationService\SimpleType;
$userCredential = new ComplexType\WebAuthenticationCredential();
$userCredential
->setKey(FEDEX_KEY)
->setPassword(FEDEX_PASSWORD);
$webAuthenticationDetail = new ComplexType\WebAuthenticationDetail();
$webAuthenticationDetail->setUserCredential($userCredential);
$clientDetail = new ComplexType\ClientDetail();
$clientDetail
->setAccountNumber(FEDEX_ACCOUNT_NUMBER)
->setMeterNumber(FEDEX_METER_NUMBER);
$version = new ComplexType\VersionId();
$version
->setMajor(2)
->setIntermediate(0)
->setMinor(0)
->setServiceId('aval');
$options = new ComplexType\AddressValidationOptions();
$options
->setCheckResidentialStatus(true)
->setVerifyAddresses(true)
->setConvertToUpperCase(true)
->setDirectionalAccuracy(SimpleType\AddressValidationAccuracyType::_MEDIUM);
$addresses = array();
$address1 = new ComplexType\Address();
$address1
->setStreetLines(array('12345 Main Street'))
->setCity('Anytown')
->setStateOrProvinceCode('NY')
->setPostalCode('47711')
->setCountryCode('US');
$addressToValidate1 = new ComplexType\AddressToValidate();
$addressToValidate1
->setAddress($address1)
->setAddressId(1);
$addresses[] = $addressToValidate1;
$addressValidationRequest = new ComplexType\AddressValidationRequest();
$addressValidationRequest->setWebAuthenticationDetail($webAuthenticationDetail);
$addressValidationRequest->setClientDetail($clientDetail);
$addressValidationRequest->setVersion($version);
$addressValidationRequest->setRequestTimestamp(date('c'));
$addressValidationRequest->setOptions($options);
$addressValidationRequest->setAddressesToValidate($addresses);
$validateShipmentRequest = new AddressValidationService\Request();
$result = $validateShipmentRequest->getAddressValidationReply($addressValidationRequest);
var_dump($result);