Visa Developer Community

Helper

Fix PHP Code in Visa Checkout using Cybersouce Payment API

Hello. Right now I always got an error response 'HTTP/1.0 411 Length Required'  when running my PHP code.

I know that my PHP code is incorrect. I cannot find any php sample code in the Cybersource/Visa Checkout documentation or a clear way how to do it correctly.

 

Here is my incorrect PHP code:

VisaCheckoutForCybersource();

function VisaCheckoutForCybersource(){
	//Hash for x-pay-token
   $time = time();
   $apikey = "myCybersourceAPIkey";
   $secret = "myCybersourceShared Secret key";
   $query_string = "apikey=".$apikey;
   $token = $secret.$time.$query_string;
   $hashtoken = "x:".$time.":".hash('sha256',$token);
   //$url = "https://sandbox.secure.checkout.visa.com/wallet-services-web/".$resource."?".$query_string;
   $url = "https://sandbox.api.visa.com/cybersource/v2/payments?".$query_string;
   
   $PaymentInformation = '{"paymentMethodType":"PAN","callid":"4722488432949012802","vInitRequest":{"apikey":"A86SKC2HI2WDUQ376LQQ21kxHydlE90VW8OmqxnEURq-7IZiE","referenceCallID":"Feb252019Feb262019SBRoom101","settings":{"locale":"en_US","review":{"message":"FP | Booking Dates: February 25, 2019 to February 26, 2019 Room Number: SBRoom101","buttonAction":"Pay"},"displayName":"HHootteeLL","dataLevel":"SUMMARY","widgetStyle":"OVERLAY","buttonPosition":"RELATIVE","shipping":{"collectShipping":"false"},"payment":{"billingCountries":["AU","GB","US"]}},"paymentRequest":{"description":"HHootteeLL VisaCheckoutPayment","currencyCode":"USD","subtotal":"70.83","tax":"14.17","total":"85.00"},"parentUrl":"http://iammarvin261a.x10host.com/wphottel1a/single-bed-2/","enableUserDataPrefill":false,"displayName":"HHootteeLL","browserLocale":"en_US","clientId":"9134ffb7-7695-1a45-83c8-163bad443f02","allowEnrollment":true,"allowSRC":true,"allowCustomBranding":false,"guestCheckout":false,"currencyFormat":"currencyCode ###,###, ###.##","logoUrl":"http://iammarvin261a.x10host.com/wphottel1a/wp-content/uploads/2017/09/HHootteeLL_logo2a.png"}}';
   $PaymentInformation = json_decode($PaymentInformation, true);
    
   $data->clientReferenceInformation->code = uniqid();
   $data->paymentInformation->fluidData->value = $PaymentInformation;
   $data->paymentInformation->fluidData->key = 'Cybersource Visa Checkout API Key from cybersource website';
   $data->processingInformation->visaCheckoutID ='4722488432949012802';
   $data->processingInformation->paymentSolution = 'visacheckout';

   //Header
   $header = (array("x-pay-token: ". $hashtoken, "Accept: application/json","Content-Type: application/json"));
   $options = array('http' => array('header' => $header, 'method' => 'POST', 'content' => $data ));

   //Update Visa Checkout Payment Data

      $context  = stream_context_create($options);
      $result = file_get_contents($url, false, $context);


      if ($http_response_header[0] != 'HTTP/1.1 200 OK'){
         echo "Error in executing Visa Checkout payment charges." . $http_response_header[0] . $result; 
      }
      else{
         echo $result;
      }
}    

Please look at my code and help me give a correct php sample code as soon as possible. thank you.

 

2 REPLIES 2
Visa Dev Moderator

Re: Fix PHP Code in Visa Checkout using Cybersouce Payment API

Hi,

 

Thanks for the inquiry. We are looking into this issue. Will keep you posted shortly.

 

Thanks,

Jai

Highlighted
Helper

Re: Fix PHP Code in Visa Checkout using Cybersouce Payment API

Ok. I can wait. Please do not make my wait longer. I only need javascript/jquery php code how to accept Visa Checkout payment using Cybersource as payment service provider.