";
$response[ 'stripe_form' ] = $result;
$response[ 'stripe_pubkey' ] = $stripe_pub_key;
$response[ 'stripe_seckey' ] = $stripe_secret_key;
$response[ 'stripe_email' ] = $custmr_email;
$response[ 'stripe_suc_url' ] = $stripe_suc_url;
$response[ 'stripe_procs_pay_txt' ] = $stripe_procs_pay_def_txt;
$response[ 'stripe_amount_text' ] = $stripe_amount_text;
$response[ 'stripe_pay_fail_text' ] = $stripe_pay_fail_def_txt;
$response[ 'stripe_pay_amount' ] = $stripe_final_amount;
$response[ 'stripe_insert_id' ] = $stripe_insert_id;
return $response;
}
function cf7wpay_footer() {
?>
200 ) );
return;
}
if(CF7WPAY_USE_SANDBOX == true) {
$paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
} else {
$paypal_url = "https://www.paypal.com/cgi-bin/webscr";
}
$validate_ipn = array('cmd' => '_notify-validate');
$validate_ipn += stripslashes_deep($ipn_response);
//Send back post vars to paypal
$params = array(
'body' => $validate_ipn,
'sslverify' => false,
'timeout' => 60,
'httpversion' => '1.1',
'compress' => false,
'decompress' => false,
'user-agent' => 'WP PayPal/' . CF7WPAY_PAYPAL_VERSION
);
$response = wp_remote_post($paypal_url, $params);
$ipn_verified = false;
if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) {
header( 'HTTP/1.1 200 OK' );
$ipn_verified = true;
// print_r($ipn_response);
// exit;
$item_name = sanitize_text_field( $ipn_response['item_name'] );
$item_number = sanitize_text_field( $ipn_response['item_number'] );
$payment_status = sanitize_text_field( $ipn_response['payment_status'] );
$payment_amount = sanitize_text_field( $ipn_response['mc_gross'] );
$payment_currency = sanitize_text_field( $ipn_response['mc_currency'] );
$txn_id = sanitize_text_field( $ipn_response['txn_id'] );
$receiver_email = sanitize_text_field( $ipn_response['receiver_email'] );
$payer_email = sanitize_text_field( $ipn_response['payer_email'] );
$form_id = sanitize_text_field( $ipn_response['custom'] );
update_post_meta($form_id,CF7WPAYPREFIX.'item_name',$item_name);
update_post_meta($form_id,CF7WPAYPREFIX.'item_name_1',$item_name_1);
update_post_meta($form_id,CF7WPAYPREFIX.'item_number',$item_number);
update_post_meta($form_id,CF7WPAYPREFIX.'payment_status',$payment_status);
update_post_meta($form_id,CF7WPAYPREFIX.'payment_amount',$payment_amount);
update_post_meta($form_id,CF7WPAYPREFIX.'payment_currency',$payment_currency);
update_post_meta($form_id,CF7WPAYPREFIX.'txn_id',$txn_id);
update_post_meta($form_id,CF7WPAYPREFIX.'receiver_email',$receiver_email);
update_post_meta($form_id,CF7WPAYPREFIX.'payer_email',$payer_email);
}
}
// stripe charge ajax call
function cf7wpay_stripe_charge() {
if ( isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST' && isset($_POST['stripeToken']) ) {
return;
}
//security verification
if ( ! check_ajax_referer( 'cf7wpay-ajax-nonce', 'cf7wpay-security', false ) ) {
wp_send_json_error( 'Invalid security token sent.' );
wp_die();
}
$token = sanitize_text_field($_POST['token']['id']);
//form id
$id = sanitize_text_field($_POST['id']);
$stripe_key = '';
$stripe_mode = get_post_meta( $id, CF7WPAYPREFIX.'enabled_stripe_Sandbox', true );
if($stripe_mode == "on") {
$stripe_key = get_post_meta( $id, CF7WPAYPREFIX.'stripe_test_secret_key', true );
} else {
$stripe_key = get_post_meta( $id, CF7WPAYPREFIX.'stripe_live_secret_key', true );
}
$currency = get_post_meta( $id, CF7WPAYPREFIX.'stripe_currency', true );
if (empty($currency)) { $currency = "USD"; }
$desc = "Demo Testing";
if(empty($desc)) {
$desc = 'Payment Using CF7';
}
$sku = "SKU_DEMO";
$amount = sanitize_text_field($_POST['pay_amount']);
if ($currency != 'JPY') {
// convert amount to cents
$amount = $amount * 100;
} else {
$amount = (int)$amount;
}
$email = sanitize_text_field($_POST['email']);
if (empty($email)) {
$email = '';
}
// default status
$status = '';
// class
\Stripe\Stripe::setApiKey($stripe_key);
// Create a charge: this will charge the user's card
try {
$customer = \Stripe\Customer::create(array(
"source" => $token,
"email" => $email
// "address" => ["city" => 'Sydney', "country" => 'Australia', "line1" => "line1", "line2" => "", "postal_code" => "2000", "state" => "New South Wales"],
// "description" => 'sadasdsa',
// "name" => 'sadsd'
));
$charge = \Stripe\Charge::create(array(
"amount" => $amount, // Amount in cents
"currency" => $currency,
"description" => $desc,
"metadata" => array("ID/SKU" => $sku),
"customer" => $customer->id,
));
$txn_id = sanitize_text_field($charge->id);
$status = 'completed';
$stripe_response = $charge->jsonSerialize();
} catch(\Stripe\Error\Card $e) {
// Since it's a decline, \Stripe\Error\Card will be caught
$body = $e->getJsonBody();
$err = $body['error'];
$reason = $err['message'];
} catch (\Stripe\Error\RateLimit $e) {
// Too many requests made to the API too quickly
$body = $e->getJsonBody();
$err = $body['error'];
$reason = $err['message'];
} catch (\Stripe\Error\InvalidRequest $e) {
// Invalid parameters were supplied to Stripe's API
$body = $e->getJsonBody();
$err = $body['error'];
$reason = $err['message'];
} catch (\Stripe\Error\Authentication $e) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
$body = $e->getJsonBody();
$err = $body['error'];
$reason = $err['message'];
} catch (\Stripe\Error\ApiConnection $e) {
// Network communication with Stripe failed
$body = $e->getJsonBody();
$err = $body['error'];
$reason = $err['message'];
} catch (\Stripe\Error\Base $e) {
// Display a very generic error to the user, and maybe send
// yourself an email
$body = $e->getJsonBody();
$err = $body['error'];
$reason = $err['message'];
} catch (Exception $e) {
// Something else happened, completely unrelated to Stripe
$body = $e->getJsonBody();
$err = $body['error'];
$reason = $err['message'];
}
// transaction failed
if ($status != 'completed') {
$status = 'failed';
$txn_id = '';
}
$stripe_status_def_txt ="Status";
if($stripe_status_def_txt != '') {
$stripe_status_txt = $stripe_status_def_txt;
} else {
$stripe_status_txt = 'Status';
}
$stripe_order_def_txt = "Order";
if($stripe_order_def_txt != '') {
$stripe_order_txt = $stripe_order_def_txt;
} else {
$stripe_order_txt = 'Order';
}
$stripe_pay_suc_def_txt = "Payment Successful";
if($stripe_pay_suc_def_txt != '') {
$stripe_pay_succ_txt = $stripe_pay_suc_def_txt;
} else {
$stripe_pay_succ_txt = 'Payment Successful';
}
$html_success = "
| ".$stripe_status_txt.": | ".$stripe_pay_succ_txt." |
| ".$stripe_order_txt." #: | ".$txn_id." |
";
$stripe_insert_id = sanitize_text_field($_POST['stripe_insert_id']);
$stripe_amount = sanitize_text_field($_POST['pay_amount']);
update_post_meta($stripe_insert_id, CF7WPAYPREFIX.'item_name', $desc);
update_post_meta($stripe_insert_id, CF7WPAYPREFIX.'item_number', $sku);
update_post_meta($stripe_insert_id, CF7WPAYPREFIX.'payment_status', $status);
update_post_meta($stripe_insert_id, CF7WPAYPREFIX.'payment_amount', $stripe_amount);
update_post_meta($stripe_insert_id, CF7WPAYPREFIX.'payment_currency', $currency);
update_post_meta($stripe_insert_id, CF7WPAYPREFIX.'txn_id', $txn_id);
$response = array(
'response' => $status,
'html_success' => $html_success,
'json_response' => $stripe_response
);
echo json_encode($response);
wp_die();
}
function init() {
add_filter( 'wpcf7_editor_panels', array( $this, 'cf7wpay_editor_panels'), 10, 1 );
add_action( 'wpcf7_after_save', array( $this, 'cf7wpay_after_save'), 10, 1 );
add_action( 'wpcf7_before_send_mail', array( $this, 'save_application_form'));
add_filter( 'wpcf7_ajax_json_echo', array( $this, 'cf7wpay_ajax_json_echo'), 20, 2 );
add_action( 'wp_footer', array($this, 'cf7wpay_footer' ));
add_action( 'wp_ajax_paypal_callback', array($this, 'cf7wpay_paypal_callback' ));
add_action( 'wp_ajax_nopriv_paypal_callback', array($this, 'cf7wpay_paypal_callback' ));
add_action('wp_ajax_cf7wpay_stripe_charge', array( $this, 'cf7wpay_stripe_charge'));
add_action('wp_ajax_nopriv_cf7wpay_stripe_charge', array($this, 'cf7wpay_stripe_charge'));
}
public static function instance() {
if (!isset(self::$instance)) {
self::$instance = new self();
self::$instance->init();
}
return self::$instance;
}
}
cfywpay_cf7_panel::instance();
}
?>