Skip to content

Instantly share code, notes, and snippets.

@uniacid
Last active August 29, 2015 14:05
Show Gist options
  • Save uniacid/7ab9e79a034adf2b5ded to your computer and use it in GitHub Desktop.
Save uniacid/7ab9e79a034adf2b5ded to your computer and use it in GitHub Desktop.
The Diamond Lining API Hook
<?php
session_start();
add_action('gform_after_submission_6', 'post_to_b79_api', 10, 2);
function post_to_b79_api($entry, $form) {
// Set phone
$phoneNumber = $entry['10'];
// Split names properly
$name_parts = explode(' ', $entry[8]);
$name_first = array_shift($name_parts);
$name_last = array_pop($name_parts);
$name_middle = trim(implode(' ', $name_parts));
$firstName = $name_first.' '.$name_middle;
$lastName = $name_last;
// Pass to GoldExchangeAPI
$url = 'http://secure.goldexchangeapi.com/';
$query = '{"apiUserName":"elitediamondbuyers","apiPassKey":"67f70d33d8b65cb79702fb7f5405b2c6","request":{"service":"CustomerService","method":"createCustomerDiamondLining","params":{"appraisalData":{"cid":"53ff5bd72ab7a","first_name":"'.$firstName.'","last_name":"'.$lastName.'","email":"'.trim($entry[9]).'","phone":"'.trim($phoneNumber).'","appraisal_notes":{"Shape":"'.$entry[1].'","Color":"'.$entry[2].'","Certification Number":"'.$entry[3].'","Clarity":"'.$entry[4].'","Number Of Diamonds":"'.$entry[5].'","Center Stone Weight":"'.$entry[6].'"}}}}}';
$url .= '?apiRequest=' . rawurlencode($query);
$response = wp_remote_get($url);
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
} else {
$result = json_decode($response['body']);
$auth_token = $result->response->result->customer->auth_token;
$_SESSION['edbAuthKey'] = $auth_token;
// echo '<pre>';
// // print_r( $response );
// print_r($auth_token);
// echo '<br>';
// // print_r($url);
// echo '</pre>';
// die();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment