Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function NVPToArray($NVPString)
- {
- $proArray = array();
- while(strlen($NVPString))
- {
- // name
- $keypos= strpos($NVPString,'=');
- $keyval = substr($NVPString,0,$keypos);
- // value
- $valuepos = strpos($NVPString,'&') ? strpos($NVPString,'&'): strlen($NVPString);
- $valval = substr($NVPString,$keypos+1,$valuepos-$keypos-1);
- // decoding the respose
- $proArray[$keyval] = urldecode($valval);
- $NVPString = substr($NVPString,$valuepos+1,strlen($NVPString));
- }
- return json_encode($proArray);
- }
- // Include config file
- $sandbox = FALSE;
- // Set PayPal API version and credentials.
- $api_version = '56.0';
- $api_endpoint = 'https://api-3t.paypal.com/nvp';
- $api_username = 'xxxxxxxxxxxxxxxx';
- $api_password = 'xxxxxxxxxxxxxxxx';
- $api_signature = 'xxxxxxxxxxxxxxx';
- // Store request params in an array
- $request_params = array
- (
- 'METHOD' => 'DoDirectPayment',
- 'USER' => $api_username,
- 'PWD' => $api_password,
- 'SIGNATURE' => $api_signature,
- 'VERSION' => $api_version,
- 'PAYMENTACTION' => 'Sale',
- 'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
- 'CREDITCARDTYPE' => 'Visa',
- 'ACCT' => '4444183269154444',
- 'EXPDATE' => '092020',
- 'CVV2' => '456',
- 'FIRSTNAME' => 'Jane',
- 'LASTNAME' => 'Doe',
- 'STREET' => '25 Pacifica',
- 'CITY' => 'Irvine',
- 'STATE' => 'CA',
- 'COUNTRYCODE' => 'US',
- 'ZIP' => '92618',
- 'AMT' => 0.1,
- 'CURRENCYCODE' => 'USD',
- 'DESC' => 'Testing Payments Pro'
- );
- // Loop through $request_params array to generate the NVP string.
- $nvp_string = '';
- foreach($request_params as $var=>$val)
- {
- $nvp_string .= '&'.$var.'='.urlencode($val);
- }
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_VERBOSE, 1);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($curl, CURLOPT_TIMEOUT, 30);
- curl_setopt($curl, CURLOPT_URL, $api_endpoint);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);
- $result = curl_exec($curl);
- $result_array = NVPToArray($result);
- print_r($result_array);exit;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement