Advertisement
Guest User

cURL request

a guest
Feb 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 KB | None | 0 0
  1. $post = [
  2.         'offer.id' => $offerID,
  3.         'subscriber.name' => $first_name,
  4.         'subscriber.surname' => $last_name,
  5.         'subscriber.email' => "",
  6.         'subscriber.phoneNumber' => $phone,
  7.         'privacyPolicyUrl' => true,
  8.         'paymentType' => 'CC',
  9.         'paymentCard.cardHolderName' => $cardholder_name,
  10.         'paymentCard.cardNumber' => $card_number,
  11.         'paymentCard.expireMonth' => $card_month,
  12.         'paymentCard.expireYear' => $card_year,
  13.         'paymentCard.cvc' => $card_cvc,
  14.         'companySiteName' => $options['site_name'],
  15.         'callbackUrl' => $options['callback_url']
  16.     ];
  17.  
  18.     $post_send = http_build_query($post, '', '&');
  19.  
  20.     $headers = [];
  21.  
  22.     $ch = curl_init('https://sandbox.subscreasy.com/na/subscription/start/4ds');
  23.     curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  24.         'Content-Type: application/x-www-form-urlencoded'
  25.     ));
  26.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  27.     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_send);
  28.     curl_setopt($ch, CURLOPT_VERBOSE, true);
  29.     curl_setopt($ch, CURLOPT_HEADER, 1);
  30.  
  31.  
  32.  
  33. // this function is called by curl for each header received
  34.     curl_setopt($ch, CURLOPT_HEADERFUNCTION,
  35.         function($curl, $header) use (&$headers)
  36.         {
  37.             $len = strlen($header);
  38.             $header = explode(':', $header, 2);
  39.             if (count($header) < 2) // ignore invalid headers
  40.                 return $len;
  41.  
  42.             $name = strtolower(trim($header[0]));
  43.             if (!array_key_exists($name, $headers))
  44.                 $headers[$name] = [trim($header[1])];
  45.             else
  46.                 $headers[$name][] = trim($header[1]);
  47.  
  48.             return $len;
  49.         }
  50.     );
  51.  
  52.     $response = curl_exec($ch);
  53.  
  54.     print_r($headers);
  55.  
  56.     curl_close($ch);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement