Created
January 28, 2019 22:54
-
-
Save enlacee/3532f0e4ad12e1de674cd1754ffb2986 to your computer and use it in GitHub Desktop.
Crear cargos posteriores
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function ajax_paymentfitnes() { | |
global $current_user; | |
get_currentuserinfo(); | |
// Check parameters | |
$message = isset( $_POST['card_token'] ) ? $_POST['card_token'] : false; | |
$dataPOST = $_POST; | |
$culqui_customer_id = get_the_author_meta( 'culqui_customer_id', $current_user->ID ); | |
// get_the_author_meta( 'culqui_customer_id', $user->ID ) ); | |
if( !$message ) { | |
wp_send_json( array('message' => __('Message not received :(', 'wpduf') ) ); | |
} else { | |
// execute payment | |
$culqi = new Culqi\Culqi(array('api_key' => PaymentFitnesCulqi::$PRIVATE_KEY)); | |
try { | |
// $culqi->Customers->delete('cus_test_ySh5eWGiJp6CAbYh'); | |
// $culqi->Customers->delete('cus_test_wE98dYCN9KFCSrDJ'); | |
// var_dump($culqi->Customers->all()); | |
//Crear Cliente | |
if ( empty( $culqui_customer_id ) === true ) { | |
$customer = $culqi->Customers->create( | |
array( | |
"address" => $_POST['address'], | |
"address_city" => "Lima", | |
"country_code" => $_POST['country_code'], | |
"email" => $_POST['email'], | |
"first_name" => $_POST['firstname'], | |
"last_name" => $_POST['lastname'], | |
"phone_number" => $_POST['phone_number'] | |
) | |
); | |
if ( is_object( $customer ) && isset( $customer->id ) === true ) { | |
update_user_meta( $current_user->ID, 'culqui_customer_id', $customer->id ); | |
$culqui_customer_id = $customer->id; | |
} | |
} | |
//Crear Tarjeta | |
$card = $culqi->Cards->create( | |
array( | |
"customer_id" => $culqui_customer_id, | |
"token_id" => $_POST['card_token'] | |
) | |
); | |
// var_dump($card->id); | |
$cantidadAPagar = (int)$_POST['amount']; | |
//Crear Cargo | |
$culqi->Charges->create( | |
array( | |
"amount" => $cantidadAPagar, | |
"currency_code" => $_POST['currency_code'], | |
"email" => "[email protected]", | |
"source_id" => $card->id | |
) | |
); | |
} catch (Exception $e) { | |
echo json_encode($e->getMessage()); | |
} | |
wp_send_json( array('message' => __('Message received, greetings from server!', 'wpduf') ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment