/** * process_subscription_payment function. * * @param WC_order $order * @param integer $amount (default: 0) * @uses Simplify_BadRequestException * @return bool|WP_Error */ public function process_subscription_payment($order, $amount = 0) { if (0 == $amount) { // Payment complete $order->payment_complete(); return true; } if ($amount * 100 < 50) { return new WP_Error('simplify_error', __('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce')); } $order_items = $order->get_items(); $order_item = array_shift($order_items); $subscription_name = sprintf(__('%s - Subscription for "%s"', 'woocommerce'), esc_html(get_bloginfo('name', 'display')), $order_item['name']) . ' ' . sprintf(__('(Order #%s)', 'woocommerce'), $order->get_order_number()); $customer_id = get_post_meta($order->id, '_simplify_customer_id', true); if (!$customer_id) { return new WP_Error('simplify_error', __('Customer not found', 'woocommerce')); } try { // Charge the customer $payment = Simplify_Payment::createPayment(array('amount' => $amount * 100, 'customer' => $customer_id, 'description' => trim(substr($subscription_name, 0, 1024)), 'currency' => strtoupper(get_woocommerce_currency()), 'reference' => $order->id, 'card.addressCity' => $order->billing_city, 'card.addressCountry' => $order->billing_country, 'card.addressLine1' => $order->billing_address_1, 'card.addressLine2' => $order->billing_address_2, 'card.addressState' => $order->billing_state, 'card.addressZip' => $order->billing_postcode)); } catch (Exception $e) { $error_message = $e->getMessage(); if ($e instanceof Simplify_BadRequestException && $e->hasFieldErrors() && $e->getFieldErrors()) { $error_message = ''; foreach ($e->getFieldErrors() as $error) { $error_message .= ' ' . $error->getFieldName() . ': "' . $error->getMessage() . '" (' . $error->getErrorCode() . ')'; } } $order->add_order_note(sprintf(__('Simplify payment error: %s', 'woocommerce'), $error_message)); return new WP_Error('simplify_payment_declined', $e->getMessage(), array('status' => $e->getCode())); } if ('APPROVED' == $payment->paymentStatus) { // Payment complete $order->payment_complete($payment->id); // Add order note $order->add_order_note(sprintf(__('Simplify payment approved (ID: %s, Auth Code: %s)', 'woocommerce'), $payment->id, $payment->authCode)); return true; } else { $order->add_order_note(__('Simplify payment declined', 'woocommerce')); return new WP_Error('simplify_payment_declined', __('Payment was declined - please try another card.', 'woocommerce')); } }
/** * do payment function. * * @param WC_order $order * @param int $amount (default: 0) * @uses Simplify_BadRequestException * @return bool|WP_Error */ public function do_payment($order, $amount = 0, $token = array()) { if ($amount * 100 < 50) { return new WP_Error('simplify_error', __('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce')); } try { // Charge the customer $data = array('amount' => $amount * 100, 'description' => sprintf(__('%1$s - Order #%2$s', 'woocommerce'), esc_html(get_bloginfo('name', 'display')), $order->get_order_number()), 'currency' => strtoupper(get_woocommerce_currency()), 'reference' => $order->get_id()); $data = array_merge($data, $token); $payment = Simplify_Payment::createPayment($data); } catch (Exception $e) { $error_message = $e->getMessage(); if ($e instanceof Simplify_BadRequestException && $e->hasFieldErrors() && $e->getFieldErrors()) { $error_message = ''; foreach ($e->getFieldErrors() as $error) { $error_message .= ' ' . $error->getFieldName() . ': "' . $error->getMessage() . '" (' . $error->getErrorCode() . ')'; } } $order->add_order_note(sprintf(__('Simplify payment error: %s', 'woocommerce'), $error_message)); return new WP_Error('simplify_payment_declined', $e->getMessage(), array('status' => $e->getCode())); } if ('APPROVED' == $payment->paymentStatus) { // Payment complete $order->payment_complete($payment->id); // Add order note $order->add_order_note(sprintf(__('Simplify payment approved (ID: %1$s, Auth Code: %2$s)', 'woocommerce'), $payment->id, $payment->authCode)); return true; } else { $order->add_order_note(__('Simplify payment declined', 'woocommerce')); return new WP_Error('simplify_payment_declined', __('Payment was declined - please try another card.', 'woocommerce')); } }
/** * Process standard payments * * @param WC_Order $order * @param string $cart_token * @uses Simplify_ApiException * @uses Simplify_BadRequestException * @return array */ protected function process_standard_payments($order, $cart_token = '') { try { if (empty($cart_token)) { $error_msg = __('Please make sure your card details have been entered correctly and that your browser supports JavaScript.', 'woocommerce'); if ('yes' == $this->sandbox) { $error_msg .= ' ' . __('Developers: Please make sure that you\'re including jQuery and there are no JavaScript errors on the page.', 'woocommerce'); } throw new Simplify_ApiException($error_msg); } $payment = Simplify_Payment::createPayment(array('amount' => $order->order_total * 100, 'token' => $cart_token, 'description' => sprintf(__('%s - Order #%s', 'woocommerce'), esc_html(get_bloginfo('name', 'display')), $order->get_order_number()), 'currency' => strtoupper(get_woocommerce_currency()), 'reference' => $order->id, 'card.addressCity' => $order->billing_city, 'card.addressCountry' => $order->billing_country, 'card.addressLine1' => $order->billing_address_1, 'card.addressLine2' => $order->billing_address_2, 'card.addressState' => $order->billing_state, 'card.addressZip' => $order->billing_postcode)); $order_complete = $this->process_order_status($order, $payment->id, $payment->paymentStatus, $payment->authCode); if ($order_complete) { // Return thank you page redirect return array('result' => 'success', 'redirect' => $this->get_return_url($order)); } else { $order->add_order_note(__('Simplify payment declined', 'woocommerce')); throw new Simplify_ApiException(__('Payment was declined - please try another card.', 'woocommerce')); } } catch (Simplify_ApiException $e) { if ($e instanceof Simplify_BadRequestException && $e->hasFieldErrors() && $e->getFieldErrors()) { foreach ($e->getFieldErrors() as $error) { wc_add_notice($error->getFieldName() . ': "' . $error->getMessage() . '" (' . $error->getErrorCode() . ')', 'error'); } } else { wc_add_notice($e->getMessage(), 'error'); } return array('result' => 'fail', 'redirect' => ''); } }
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* Instructions: * 1. Replace public key and private key with your respective API keys * 2. This sample code charges $10 to the card token submitted. You can pass the charge parameter by uncommenting * the charge parameter */ header('Content-Type: application/json'); error_reporting(E_ALL); require_once "./lib/Simplify.php"; Simplify::$publicKey = 'YOUR_PUBLIC_API_KEY'; // such as 'sbpb_MzIxYmFjYzItYThiYS00ZDA3LTllZTctY2ZjYjIxY2QzYWMw'; Simplify::$privateKey = 'YOUR_PRIVATE_API_KEY'; // such as 'gEEh+NSgYUi4dqG+u3F3iTuOK4n1L01StM60skz7CUR5YFFQL0ODSXAOkNtXTToq'; $token = $_POST['simplifyToken']; //You can get the charge from the client by uncommenting line below // $charge = $_POST['charge']; $charge = 1000; // charges $10 $c = array('amount' => $charge, 'token' => $token, 'description' => 'product description', 'currency' => 'USD'); try { $charge = Simplify_Payment::createPayment($c); $chargeId = $charge->{'id'}; echo $charge->{'paymentStatus'} . " charged :" . $charge->{'amount'} / 100; } catch (Exception $e) { echo ' Caught exception: ', $e->getMessage(), "\n", $e; }
/** * Process a pre-order payment when the pre-order is released. * * @param WC_Order $order * @return wp_error|null */ public function process_pre_order_release_payment($order) { try { $order_items = $order->get_items(); $order_item = array_shift($order_items); $pre_order_name = sprintf(__('%s - Pre-order for "%s"', 'woocommerce'), esc_html(get_bloginfo('name', 'display')), $order_item['name']) . ' ' . sprintf(__('(Order #%s)', 'woocommerce'), $order->get_order_number()); $customer_id = get_post_meta($order->id, '_simplify_customer_id', true); if (!$customer_id) { return new WP_Error('simplify_error', __('Customer not found', 'woocommerce')); } // Charge the customer $payment = Simplify_Payment::createPayment(array('amount' => $order->order_total * 100, 'customer' => $customer_id, 'description' => trim(substr($pre_order_name, 0, 1024)), 'currency' => strtoupper(get_woocommerce_currency()), 'reference' => $order->id)); if ('APPROVED' == $payment->paymentStatus) { // Payment complete $order->payment_complete($payment->id); // Add order note $order->add_order_note(sprintf(__('Simplify payment approved (ID: %s, Auth Code: %s)', 'woocommerce'), $payment->id, $payment->authCode)); } else { return new WP_Error('simplify_payment_declined', __('Payment was declined - the customer need to try another card.', 'woocommerce')); } } catch (Exception $e) { $order_note = sprintf(__('Simplify Transaction Failed (%s)', 'woocommerce'), $e->getMessage()); // Mark order as failed if not already set, // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times if ('failed' != $order->get_status()) { $order->update_status('failed', $order_note); } else { $order->add_order_note($order_note); } } }
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <?php try { $nombre = $_POST['nombre']; $apellidos = $_POST['apellidos']; $dir = $_POST['direccion']; $telefono = $_POST['telefono']; $correo = $_POST['correo']; (string) ($numtarj = $_POST['numtarj']); $mv = $_POST['mesv']; $av = $_POST['aniov']; $cs = $_POST['cs']; $prop = $_POST['propietario']; $con = $_POST['concepto']; $total = $_POST['total']; require_once "simplify/lib/Simplify.php"; Simplify::$publicKey = 'sbpb_MDhjZmRmNmQtMTJlZC00NmQ1LWI4NDYtZjRhZTg1NjgzZjVi'; Simplify::$privateKey = 'Q65+PyW5h8jdhFECaykl95C7HNO/PgvqWV5gUDFlGSt5YFFQL0ODSXAOkNtXTToq'; $payment = Simplify_Payment::createPayment(array("card" => array("number" => $numtarj, "expMonth" => $mv, "expYear" => $av, "cvc" => $cs), 'amount' => $total, 'description' => $con, 'currency' => 'USD')); if ($payment->paymentStatus == 'APPROVED') { echo "<center>"; echo "<p style='font-size: 50px;'><strong>Slyfer</strong></p>"; echo "<i class='fa fa-refresh fa-spin fa-5x'></i>"; echo "<p style='font-size: 20px;'><strong>Procesando Tu pago espera unos segundos...</strong></p>"; echo "</center>"; header('refresh:10; url=paysucefull.php'); } } catch (Exception $e) { echo $e; }
/** * Use this to do the final payment. Create the order then process the payment. If * you know the payment is successful right away go ahead and change the order status * as well. * Call $mp->cart_checkout_error($msg, $context); to handle errors. If no errors * it will redirect to the next step. * * @param array $cart. Contains the cart contents for the current blog, global cart if $mp->global_cart is true * @param array $shipping_info. Contains shipping info and email in case you need it */ function process_payment($cart, $shipping_info) { global $mp; $settings = get_option('mp_settings'); // Token MUST be set at this point if (!isset($_SESSION['simplifyToken'])) { $mp->cart_checkout_error(__('The Simplify Token was not generated correctly. Please go back and try again.', 'mp')); return false; } // Setup the Simplify API if (!class_exists('Simplify')) { require_once $mp->plugin_dir . "plugins-gateway/simplify-files/lib/Simplify.php"; } Simplify::$publicKey = $this->publishable_key; Simplify::$privateKey = $this->private_key; $totals = array(); $coupon_code = $mp->get_coupon_code(); foreach ($cart as $product_id => $variations) { foreach ($variations as $variation => $data) { $price = $mp->coupon_value_product($coupon_code, $data['price'] * $data['quantity'], $product_id); $totals[] = $price; } } $total = array_sum($totals); //shipping line $shipping_tax = 0; if (($shipping_price = $mp->shipping_price(false)) !== false) { $total += $shipping_price; $shipping_tax = $mp->shipping_tax_price($shipping_price) - $shipping_price; } //tax line if tax inclusive pricing is off. It it's on it would screw up the totals if (!$mp->get_setting('tax->tax_inclusive')) { $tax_price = $mp->tax_price(false) + $shipping_tax; $total += $tax_price; } $order_id = $mp->generate_order_id(); try { $token = $SESSION['simplifyToken']; $charge = Simplify_Payment::createPayment(array('amount' => $total * 100, 'token' => $_SESSION['simplifyToken'], 'description' => sprintf(__('%s Store Purchase - Order ID: %s, Email: %s', 'mp'), get_bloginfo('name'), $order_id, $_SESSION['mp_shipping_info']['email']), 'currency' => $this->currency)); if ($charge->paymentStatus == 'APPROVED') { $payment_info = array(); $payment_info['gateway_public_name'] = $this->public_name; $payment_info['gateway_private_name'] = $this->admin_name; $payment_info['method'] = sprintf(__('%1$s Card ending in %2$s - Expires %3$s', 'mp'), $charge->card->type, $charge->card->last4, $charge->card->expMonth . '/' . $charge->card->expYear); $payment_info['transaction_id'] = $charge->id; $timestamp = time(); $payment_info['status'][$timestamp] = __('Paid', 'mp'); $payment_info['total'] = $total; $payment_info['currency'] = $this->currency; $order = $mp->create_order($order_id, $cart, $_SESSION['mp_shipping_info'], $payment_info, true); unset($_SESSION['simplifyToken']); $mp->set_cart_cookie(array()); } } catch (Exception $e) { unset($_SESSION['simplifyToken']); $mp->cart_checkout_error(sprintf(__('There was an error processing your card: "%s". Please <a href="%s">go back and try again</a>.', 'mp'), $e->getMessage(), mp_checkout_step_url('checkout'))); return false; } }
<?php require_once "./lib/Simplify.php"; Simplify::$publicKey = 'sbpb_YmFhN2JmZTMtZDBkZi00MzA5LWI5M2EtYTBjNjlkNTE3ZTVm'; Simplify::$privateKey = 'Eu/MTPwWMsL97YuJ5XCI8oIW0Sl7uGskdUbY4VXsWsx5YFFQL0ODSXAOkNtXTToq'; $payment = Simplify_Payment::createPayment(array('amount' => floatval($_POST["amount"]) * 100, 'token' => $_POST["simplifyToken"], 'description' => 'One-time Single Donation', 'reference' => '7a6ef6be31', 'currency' => 'USD')); if ($payment->paymentStatus == 'APPROVED') { echo "Payment approved\n"; } echo $_GET["simplifyToken"]; ?>
<?php require_once "./lib/Simplify.php"; /* number "5555555555554444" expmonth 11 expyear 15 cvc 123 */ $number = $_POST["number"]; $expMonth = $_POST["expMonth"]; $expYear = $_POST["expYear"]; $cvc = $_POST["cvc"]; $amount = $_POST["amount"]; $description = $_POST["description"]; Simplify::$publicKey = 'sbpb_ZjMyMTI0MGItMDc4YS00MDdiLWI0MmQtMWMyNWNlZGYzNGZj'; Simplify::$privateKey = 'DyQ6iAM7BBDJGpJPVopUWMAe+QcgNfPriHeonuJ8J7x5YFFQL0ODSXAOkNtXTToq'; $payment = Simplify_Payment::createPayment(array("card" => array("number" => $number, "expMonth" => $expMonth, "expYear" => $expYear, "cvc" => $cvc), 'amount' => $amount, 'description' => $description, 'currency' => 'USD')); if ($payment->paymentStatus == 'APPROVED') { header('Content-type: application/json'); $result = "done"; echo json_encode($result); } else { header('Content-type: application/json'); $result = "fail"; echo json_encode($result); die; }
<?php require_once "simplifycommerce/lib/Simplify.php"; Simplify::$publicKey = 'sbpb_ZDQ3ZjU3N2ItNWY5My00ZWU1LWI3NjUtMzNiMTQyMjc3NmVm'; Simplify::$privateKey = 'cl5KEXyHM7tgQDBP6XiMjaVEgAAPsHxEnnGlNF1xdxt5YFFQL0ODSXAOkNtXTToq'; $payment = Simplify_Payment::createPayment(array('amount' => $_REQUEST['amount'], 'token' => $_REQUEST['token'], 'description' => $_REQUEST['description'], 'reference' => '7a6ef6be31', 'currency' => 'USD')); if ($payment->paymentStatus == 'APPROVED') { echo "Payment approved\n"; }
function process_payment($cart) { global $tc; $this->maybe_start_session(); $this->save_cart_info(); if (isset($_POST['simplify_payment_form']) && $_POST['simplify_payment_form'] == 'not_available') { $_SESSION['tc_gateway_error'] = __('The Simplify Commerce is not available at the moment. Please try another method or contact the admnistrator', 'tc-sc'); wp_redirect($tc->get_payment_slug(true)); tc_js_redirect($tc->get_payment_slug(true)); return false; } if (!isset($_POST['simplifyToken'])) { $_SESSION['tc_gateway_error'] = __('The Simplify Commerce Token was not generated correctly. Please go back and try again.', 'tc'); wp_redirect($tc->get_payment_slug(true)); tc_js_redirect($tc->get_payment_slug(true)); return false; } $_SESSION['simplifyToken'] = $_POST['simplifyToken']; require_once $tc->plugin_dir . "/includes/gateways/simplify/Simplify.php"; //generate a tickera order id $order_id = $tc->generate_order_id(); Simplify::$publicKey = $this->public_key; Simplify::$privateKey = $this->private_key; try { $payment = Simplify_Payment::createPayment(array('amount' => $this->total() * 100, 'token' => $_SESSION['simplifyToken'], 'description' => $this->cart_items(), 'reference' => $order_id, 'currency' => $this->currency)); if ($payment->paymentStatus == 'APPROVED') { $payment_info = array(); $payment_info['transaction_id'] = $payment->id; $payment_info = $this->save_payment_info(); $tc->create_order($order_id, $this->cart_contents(), $this->cart_info(), $payment_info, true); wp_redirect($tc->get_confirmation_slug(true, $order_id)); tc_js_redirect($tc->get_confirmation_slug(true)); exit; } else { if ($payment->paymentStatus == 'DECLINED') { //run if the card is declined etc. // $_SESSION['tc_gateway_error'] = apply_filters('tc_simplify_declined_card', __('We\'re very sorry but the card you entered was declined ', 'tc-sc')); wp_redirect($tc->get_payment_slug(true)); tc_js_redirect($tc->get_payment_slug(true)); exit; } } } catch (Simplify_ApiException $e) { unset($_SESSION['simplifyToken']); $_SESSION['tc_gateway_error'] = sprintf(__('There was an error processing your card - "%s".', 'tc'), $e->getMessage()); wp_redirect($tc->get_payment_slug(true)); tc_js_redirect($tc->get_payment_slug(true)); exit; } return false; }
$description .= $merchant->products[$productId]->name . ":\$" . number_format($merchant->products[$productId]->price / 100, 2) . "X" . $quantity . ","; } $description .= $address . " " . $city . " " . $state . " " . $zip; session_destroy(); try { Simplify::$publicKey = $simplifyPublicKey; Simplify::$privateKey = $simplifyPrivateKey; // if the save card details flag is set if ($_REQUEST['saveCardDetails'] == true && isset($customerName) == true && isset($customerEmail) == true) { // create a customer $customer = Simplify_Customer::createCustomer(array('token' => $simplifyToken, 'email' => $customerEmail, 'name' => $customerName, 'reference' => 'Simplify Cake customer')); // make a payment with the customer $payment = Simplify_Payment::createPayment(array('amount' => $totalAmount, 'description' => $description, 'currency' => 'USD', 'customer' => $customer->id)); } else { // make a payment with a card token $payment = Simplify_Payment::createPayment(array('amount' => $totalAmount, 'token' => $simplifyToken, 'description' => $description, 'currency' => 'USD')); } } catch (Exception $e) { //Something wrong //Error handling needed //echo $e; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Checkout - <?php echo $merchant->name; ?>
header('Content-Type: application/json'); error_reporting(E_ALL); require_once "./sdk/lib/Simplify.php"; Simplify::$publicKey = getenv('SIMPLIFY_API_PUBLIC_KEY'); Simplify::$privateKey = getenv('SIMPLIFY_API_PRIVATE_KEY'); if (!isset($_POST["amount"]) || !isset($_POST['simplifyToken'])) { echo "Please submit POST values with amount & simplifyToken params!"; return; } $token = $_POST['simplifyToken']; $payment = $_POST["amount"]; $currency = isset($_POST["currency"]) ? $_POST["currency"] : 'USD'; $paymentPayload = array('amount' => $payment, 'token' => $token, 'description' => 'Test payment', 'currency' => $currency); $response = array(); try { $payment = Simplify_Payment::createPayment($paymentPayload); if ($payment->paymentStatus == 'APPROVED') { $response["id"] = $payment->{'id'}; } $response["status"] = $payment->paymentStatus; } catch (Exception $e) { //error handling if ($e instanceof Simplify_ApiException) { $response["reference"] = $e->getReference(); $response["message"] = $e->getMessage(); $response["errorCode"] = $e->getErrorCode(); } if ($e instanceof Simplify_BadRequestException && $e->hasFieldErrors()) { $fieldErrors = ''; foreach ($e->getFieldErrors() as $fieldError) { $fieldErrors = $fieldErrors . $fieldError->getFieldName() . ": '" . $fieldError->getMessage() . "' (" . $fieldError->getErrorCode() . ")";