UPS API Endpoints a me ka laʻana PHP hōʻike Code

ups api endpoints php ho'āʻo code address validation

Ke hana nei mākou me a WooCommerce ka mea kūʻai i kēia manawa nona Hoʻouna UPS ʻO ka hoʻopaʻa ʻana i ka helu wahi a me ka helu ʻana i nā kumukūʻai hoʻouna ua pau ka hana. ʻO ka pilikia mua a mākou i ʻike ai ʻo ka UPS shipping plugin i loaʻa iā lākou ua kahiko ʻia a ʻo ke kahua koʻikoʻi no ka hui nāna i hoʻomohala iā ia he malware… ʻaʻole ia he hōʻailona maikaʻi. No laila, kūʻai mākou i ka WooCommerce UPS plugin ʻoiai ua kākoʻo maikaʻi ʻia e nā mea hoʻomohala o Woocommerce.

Me ka pūnaewele ʻaʻole i hōʻoia i nā helu a i ʻole ka hoʻohui ʻana i ka hoʻouna ʻana, ʻo kā mākou hana mua ʻo ia ka hōʻoia ʻana i ke kikowaena polokalamu polokalamu UPS (API) ua ala a hana. He kahua maikaʻi ko UPS no ka nānā ʻana i ka kūlana o kāna API.

No ka mea ʻaʻole i hoʻokō ʻia ka API, ʻo kā mākou hana aʻe ʻo ka debug i ka pilikia ma ka ʻāina. ʻO ka mea hoihoi, ʻaʻohe plugin i hoʻopaʻa inoa a hoʻāʻo paha e ʻike inā ua hana maoli ka hoʻohui ʻana o ka UPS. ʻAʻole i hāʻawi mai ka hoʻonohonoho debug i nā manaʻo manaʻo, ʻaʻole hoʻi i kā mākou mau faila log. No laila, i mea e hoʻāʻo ai i ka API, pono wau e hoʻolālā i kahi palapala e hoʻāʻo maoli i ka API.

Ua kiʻi wau i ka UPS API Mea hoʻomohala Kit… i komo pū me nā laʻana code… a huikau e like me ka wā ma mua. Ua kaupalena ʻia ka palapala, ʻaʻole i helu ʻia nā helu hope no ka API, a ʻaʻole i kākau maikaʻi ʻia nā code code.

Hoʻoiho i ka UPS API Developer Kit

ʻO ka hopena, pono wau e hana i kekahi eli… ʻo ka mea mua ka ʻike ʻana i nā hopena no kā lākou API. Ua loaʻa iaʻu nā helu hoʻāʻo i kākau ʻia, kākau i kaʻu code, a hoʻāʻo iā ia… me ka kūleʻa ʻole. ʻEli hou aʻe a ʻike wau he mea ʻole nā ​​​​hopena hoʻāʻo. ʻAe.

UPS API Hopena

Ua hiki iaʻu ke loaʻa i kahi pae ma kahi kahua hoʻomohala i papa inoa i ka ʻO nā wahi hoʻopau hana UPS API:

  • https://onlinetools.ups.com/ups.app/xml/TimeInTransit
  • https://onlinetools.ups.com/ups.app/xml/License
  • https://onlinetools.ups.com/ups.app/xml/QVEvents
  • https://onlinetools.ups.com/ups.app/xml/Register
  • https://onlinetools.ups.com/ups.app/xml/AV
  • https://onlinetools.ups.com/ups.app/xml/ShipAccept
  • https://onlinetools.ups.com/ups.app/xml/Void
  • https://onlinetools.ups.com/ups.app/xml/XAV
  • https://onlinetools.ups.com/ups.app/xml/Track
  • https://onlinetools.ups.com/ups.app/xml/Rate
  • https://onlinetools.ups.com/ups.app/xml/ShipConfirm
  • https://onlinetools.ups.com/ups.app/xml/LabelRecovery

ʻO ka mea maʻalahi loa e hoʻāʻo ʻo ia ka Hōʻoia Wahi ( wiwo ʻole ma luna) hope no laila ua hoʻohana au i ke code i hāʻawi ʻia e kākau i kahi palapala PHP liʻiliʻi i hala i ka helu wahi a pane aku me ka kūleʻa a hāʻule paha. Eia ke code inā makemake ʻoe e hoʻohana:

UPS API PHP ho'āʻo waihona no ka helu wahi

Eia ka palapala PHP hou no ka hoao ana i ka Address Validation UPS API Endpoint:

<html>
<head>UPS Address Validation Test</head>
<body>Response: <?php

// Configuration
$accessLicenseNumber = "Insert Your API Key";
$userId = "Insert Your User ID";
$password = "Insert Your Password";

$endpointurl = 'https://onlinetools.ups.com/ups.app/xml/AV';

try {
	
	// Create AccessRequest XMl
	$accessRequestXML = new SimpleXMLElement ( "<AccessRequest></AccessRequest>" );
	$accessRequestXML->addChild ( "AccessLicenseNumber", $accessLicenseNumber );
	$accessRequestXML->addChild ( "UserId", $userId );
	$accessRequestXML->addChild ( "Password", $password );
	
	// Create AddressValidationRequest XMl
	$avRequestXML = new SimpleXMLElement ( "<AddressValidationRequest ></AddressValidationRequest >" );
	$request = $avRequestXML->addChild ( 'Request' );
	$request->addChild ( "RequestAction", "AV" );
	
	$address = $avRequestXML->addChild ( 'Address' );
	$address->addChild ( "City", "ALPHARETTA" );
	$address->addChild ( "PostalCode", "300053778" );
	$requestXML = $accessRequestXML->asXML () . $avRequestXML->asXML ();
	
	$form = array (
			'http' => array (
					'method' => 'POST',
					'header' => 'Content-type: application/x-www-form-urlencoded',
					'content' => "$requestXML" 
			) 
	);
	
	// get request
	$request = stream_context_create ( $form );
	$browser = fopen ( $endpointurl, 'rb', false, $request );
	if (! $browser) {
		throw new Exception ( "Connection failed." );
	}
	
	// get response
	$response = stream_get_contents ( $browser );
	fclose ( $browser );
	
	if ($response == false) {
		throw new Exception ( "Bad data." );
	} else {
		
		// get response status
		$resp = new SimpleXMLElement ( $response );
		echo $resp->Response->ResponseStatusDescription . "\n";
	}
	
} catch ( Exception $ex ) {
	echo $ex;
}

?>
</body>
</html>

E hōʻike ana kēia palapala iā ʻoe inā paha e hana ana ʻoe i nā hōʻoia me ka UPS API Address Validation endpoint. ʻIke wau i ka PHP methodology (fopen) e hoʻouna i kā lākou API he ʻelemakule ma kēia hiʻohiʻona ma luna ... akā makemake wau e hana i kā lākou code test.

Hōʻike: Ke hoʻohana nei wau i kaʻu WooCommerce nā loulou pili i kēia ʻatikala.