/** * @param int $order_id * @return array */ function process_payment($order_id) { $order = new jigoshop_order($order_id); $this->init_paymentwall_configs(); $return = array('result' => 'fail', 'redirect' => ''); $charge = new Paymentwall_Charge(); try { $charge->create(array_merge($this->prepare_user_profile_data($order), $this->prepare_card_info($order))); $response = $charge->getPublicData(); if ($charge->isSuccessful()) { if ($charge->isCaptured()) { // Add order note $order->add_order_note(sprintf(__('Brick payment approved (ID: %s, Card: xxxx-%s)', PW_JIGO_TEXT_DOMAIN), $charge->getId(), $charge->getCard()->getAlias())); // Payment complete $order->payment_complete(); $return['result'] = 'success'; $checkout_redirect = apply_filters('jigoshop_get_checkout_redirect_page_id', jigoshop_get_page_id('thanks')); $return['redirect'] = add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink($checkout_redirect))); } elseif ($charge->isUnderReview()) { $order->update_status('on-hold'); } // Clear shopping cart jigoshop_cart::empty_cart(); } else { $errors = json_decode($response, true); jigoshop::add_error(__($errors['error']['message']), 'error'); } } catch (Exception $e) { jigoshop::add_error($e->getMessage(), 'error'); } // Return redirect return $return; }
function paymentwallbrick_capture($params) { if (!class_exists("Paymentwall_Config")) { require_once dirname(__FILE__) . "/paymentwallbrick/lib/paymentwall.php"; } if ($params["test_mode"] == "on") { Paymentwall_Config::getInstance()->set(array('api_type' => Paymentwall_Config::API_GOODS, 'public_key' => $params['test_public_key'], 'private_key' => $params['test_private_key'])); } else { Paymentwall_Config::getInstance()->set(array('api_type' => Paymentwall_Config::API_GOODS, 'public_key' => $params['public_key'], 'private_key' => $params['private_key'])); } $email = $params['clientdetails']['email']; $charge = new Paymentwall_Charge(); if (isset($_POST['brick_token'])) { $charge->create(array('email' => $email, 'currency' => $params['currency'], 'capture' => true, 'amount' => $params['amount'], 'fingerprint' => $_POST['brick_fingerprint'], 'token' => $_POST['brick_token'], 'plan' => $params["invoiceid"], 'description' => "Payment of Invoice #" . $params['invoiceid'])); update_query("tblclients", array("cardtype" => $charge->card->type, "gatewayid" => $charge->card->token, "cardlastfour" => $charge->card->last4), array("id" => $params['clientdetails']['id'])); } else { $charge->create(array('token' => $params['gatewayid'], 'email' => $email, 'currency' => $params['currency'], 'capture' => true, 'amount' => $params['amount'], 'plan' => $params["invoiceid"], 'description' => "Payment of Invoice #" . $params['invoiceid'])); } if ($charge->isSuccessful()) { if ($charge->isCaptured()) { return array('status' => 'success', 'transid' => $charge->id); } elseif ($charge->isUnderReview()) { $_SESSION['paywall_pending_review'] = true; $_SESSION['paymentwall_errors'] = "Your payment is currently under review, you will be notified via email within two minutes if your transaction is approved."; return array('status' => 'error', 'rawdata' => $errors['error']['message']); } } else { $response = $charge->getPublicData(); $errors = json_decode($response, true); $_SESSION['paymentwall_errors'] = $errors['error']['message']; return array('status' => 'error', 'rawdata' => $errors['error']['message']); } }
/** * Validate Brick request */ public function validate() { $this->load->model('checkout/order'); $this->load->model('payment/brick'); $this->load->model('account/activity'); $this->load->model('setting/setting'); $this->language->load('payment/brick'); $defaultConfigs = $this->model_setting_setting->getSetting('config'); $data = array('status' => 'error', 'message' => '', 'redirect' => false); if (!isset($this->session->data['order_id']) || !isset($this->request->post['cc_brick_token']) || !isset($this->request->post['cc_brick_token'])) { $data['message'] = "Oops, Something went wrong. Please try again!"; } elseif ($orderInfo = $this->model_checkout_order->getOrder($this->session->data['order_id'])) { if ($this->customer->isLogged()) { $activity_data = array('customer_id' => $this->customer->getId(), 'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName(), 'order_id' => $this->session->data['order_id']); $this->model_account_activity->addActivity('order_account', $activity_data); } else { $activity_data = array('name' => $this->session->data['guest']['firstname'] . ' ' . $this->session->data['guest']['lastname'], 'order_id' => $this->session->data['order_id']); $this->model_account_activity->addActivity('order_guest', $activity_data); } $this->model_payment_brick->initBrickConfig(); $charge = new Paymentwall_Charge(); $charge->create(array_merge($this->prepareCardInfo($orderInfo), $this->getUserProfileData($orderInfo))); $response = $charge->getPublicData(); if ($charge->isSuccessful()) { if ($charge->isCaptured()) { $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('brick_complete_status'), 'The order approved, Transaction ID: #' . $charge->getId(), true); $data['message'] = $this->language->get('text_order_processed'); } elseif ($charge->isUnderReview()) { $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('brick_under_review_status'), 'The order is under review!', true); $data['message'] = $this->language->get('text_order_under_review'); } $data['status'] = 'success'; $data['redirect'] = $this->url->link('checkout/success'); } else { $response = json_decode($response, true); $data['message'] = $response['error']['message']; } } else { $data['message'] = $this->language->get('text_order_invalid'); } $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode($data)); }
/** * Submit a payment through the PaymentWall Library. * * @param mixed $data * * @return Response */ public function sendData($data) { // Initialise the PaymentWall configuration $this->setPaymentWallObject(); // if no token exists, create one if (empty($data['purchase']['token'])) { // Create a one time token $tokenModel = new \Paymentwall_OneTimeToken(); $tokenObject = $tokenModel->create($data['card']); if ($tokenObject->type == 'Error') { return $this->returnError($tokenObject->error, $tokenObject->code); } $data['purchase']['token'] = $tokenObject->getToken(); } if (empty($data['purchase']['token'])) { return $this->returnError('Payment Token could not be created', 231); } // Now we know that we have an actual token (one time or // permanent), we can create the charge request. $charge = new \Paymentwall_Charge(); try { $charge->create($data['purchase']); } catch (\Exception $e) { return $this->returnError('Cannot process payment', 231, $charge->getResponseLogInformation()); } // Force the charge properties to be an array $properties = $charge->getProperties(); $properties = json_decode(json_encode($properties), true); // Construct the response object $this->response = new Response($this, $properties); if ($charge->isSuccessful()) { if ($charge->isCaptured()) { $this->response->setCaptured(true); } elseif ($charge->isUnderReview()) { $this->response->setUnderReview(true); } } return $this->response; }
// Prepare form data $smartyvalues["client"] = $invoiceData['clientsdetails']; $smartyvalues['months'] = $gateways->getCCDateMonths(); $smartyvalues['years'] = $gateways->getCCExpiryDateYears(); $smartyvalues['invoice'] = $invoiceData; $smartyvalues['invoiceItems'] = $invoice->getLineItems(); if ($_POST['fromCCForm'] == 'true') { # Check form submit & capture payment $cardInfo = array('email' => $invoiceData['clientsdetails']['email'], 'amount' => $post['amount'], 'currency' => $post["currency"], 'token' => $_POST['brick_token'], 'fingerprint' => $_POST['brick_fingerprint'], 'description' => $invoiceData['pagetitle']); $charge = new Paymentwall_Charge(); $charge->create(array_merge($cardInfo, brick_get_user_profile_data($invoiceData))); $response = $charge->getPublicData(); if ($charge->isSuccessful()) { if ($charge->isCaptured()) { addInvoicePayment($_POST["invoiceid"], $charge->getId(), null, null, 'brick'); } elseif ($charge->isUnderReview()) { // decide on risk charge } logTransaction($gateway['name'], $cardInfo, "Successful"); $smartyvalues["success"] = true; } else { $error = json_decode($response, true); $smartyvalues["processingerror"] = '<li>' . $error['error']['message'] . '</li>'; logTransaction($gateway['name'], $cardInfo, "Unsuccessful"); } } } else { // User is logged in but they shouldn't be here (i.e. they weren't here from an invoice) header("Location: " . $CONFIG['SystemURL'] . "/clientarea.php?action=details"); } } else {
/** * Validates the incoming POST/GET response from the gateway to ensure it is * legitimate and can be trusted. * * @param array $get The GET data for this request * @param array $post The POST data for this request * @return array An array of transaction data, sets any errors using Input if the data fails to validate * - client_id The ID of the client that attempted the payment * - amount The amount of the payment * - currency The currency of the payment * - invoices An array of invoices and the amount the payment should be applied to (if any) including: * - id The ID of the invoice to apply to * - amount The amount to apply to the invoice * - status The status of the transaction (approved, declined, void, pending, reconciled, refunded, returned) * - reference_id The reference ID for gateway-only use with this transaction (optional) * - transaction_id The ID returned by the gateway to identify this transaction * - parent_transaction_id The ID returned by the gateway to identify this transaction's original transaction (in the case of refunds) */ public function validate(array $get, array $post) { if (!isset($get['data'])) { return false; } $data = $this->decodeData($get['data']); unset($get['data']); list($company_id, $payment_method) = $get; if ($payment_method != 'brick') { return false; } $brick = $post['brick']; $this->initPaymentwallConfigs(); $status = 'error'; $cardInfo = array('email' => $data['email'], 'amount' => $data['amount'], 'currency' => $data['currency'], 'description' => $data['description'], 'token' => $brick['token'], 'fingerprint' => $brick['fingerprint']); $charge = new Paymentwall_Charge(); $charge->create($cardInfo); $response = json_decode($charge->getPublicData(), true); if ($charge->isSuccessful()) { if ($charge->isCaptured()) { // deliver a product $status = 'approved'; } elseif ($charge->isUnderReview()) { // decide on risk charge $status = 'pending'; } } else { $_SESSION['brick_errors'] = $response['error']['message']; } return array('client_id' => $data['client_id'], 'amount' => $data['amount'], 'currency' => $data['currency'], 'status' => $status, 'reference_id' => null, 'transaction_id' => $charge->getId() ? $charge->getId() : false, 'parent_transaction_id' => null, 'invoices' => $data['invoices']); }