UPS API Ƙarshen Matsalolin da Samfuran Lambar Gwajin PHP

ups api endpoints php gwajin lambar adireshin inganci

Muna aiki tare da a WooCommerce abokin ciniki a yanzu wanda UPS sufuri Tabbatar da adireshi da lissafin farashin jigilar kaya sun daina aiki. Batu na farko da muka gano shi ne kayan aikin jigilar kayayyaki na UPS da suke da shi ya tsufa kuma babban yanki na kamfanin da ya haɓaka yana da malware… wannan ba alama ce mai kyau ba. Don haka, mun sayi WooCommerce UPS plugin tunda masu haɓaka Woocommerce suna samun tallafi sosai.

Tare da rukunin yanar gizon baya inganta adireshi ko haɗa jigilar kaya, matakinmu na farko shine tabbatar da cewa aikace-aikacen aikace-aikacen UPSAPI) ya tashi kuma yana aiki. UPS yana da kyakkyawan wuri don bincika matsayin API ɗin sa.

Tun da API ɗin bai bayyana an yi shi ba, mataki na gaba shine mu gyara batun a cikin gida. Abin sha'awa shine, babu plugin ɗin yana da wani shiga ko gwaji don ganin ko haɗin kai na UPS ya yi aiki da gaske. Ko da saitin gyara kuskure bai bayar da wani ra'ayi ba, haka ma fayilolin log ɗin mu. Don haka, don gwada API ɗin, dole ne in tsara rubutun don a zahiri gwada API.

Na sauke da UPS API Developer Kit… wanda ya haɗa da samfuran code… kuma ya rikice kamar koyaushe. Takaddun yana da iyaka, maƙasudin ƙarshen API ɗin ba ma a jera su ba, kuma samfuran lambar ba su da cikakkun bayanai.

Zazzage Kit ɗin Haɓaka API na UPS

A sakamakon haka, dole ne in yi wasu tono… na farko shine gano ƙarshen ƙarshen API ɗin su. Na sami bayanan ƙarshen gwaji, na rubuta lambata, na gwada ta… ba tare da nasara ba. Ƙarin ƙarin tono kuma na gano cewa ƙarshen gwajin ba su da amfani. Ugh

UPS API Ƙarshen wuraren

Na sami damar samun zaren a kan wani rukunin ci gaba wanda ya jera abubuwan Ƙarshen samar da API na UPS:

  • 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

Mafi sauƙin wanda za a gwada shine Tabbatar da Adireshi (mai ƙarfi a sama) ƙarshen ƙarshen don haka na yi amfani da lambar da aka bayar don rubuta ƙaramin rubutun PHP wanda ya wuce adireshin kuma na amsa da ko an yi nasara ko a'a. Ga lambar a yayin da kuke son amfani da ita:

UPS API Fayil ɗin Gwajin PHP don Tabbatar da Adireshi

Anan ga rubutun PHP da aka sabunta don gwada Tabbatar da Adireshin Ƙarshen Ƙarshen UPS API:

<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>

Wannan rubutun zai aƙalla nuna muku ko kuna aiki tare da UPS API Adireshin Tabbatar da Ƙarshen Ƙarshen. Na gane hanyar PHP (fopen) don aikawa zuwa API ɗin su ya ɗan tsufa a cikin wannan misalin da ke sama… amma kawai ina so in sami lambar gwajin su ta aiki.

Bayyanawa: Ina amfani da nawa WooCommerce hanyoyin haɗin gwiwa a cikin wannan labarin.