public function runConfigurationTest() { $this->loadWePayAPILibraries(); WePay::useStaging($this->getWePayClientID(), $this->getWePayClientSecret()); $wepay = new WePay($this->getWePayAccessToken()); $params = array('client_id' => $this->getWePayClientID(), 'client_secret' => $this->getWePayClientSecret()); $wepay->request('app', $params); }
/** * Used to make an API call * * @param $access_token * @param $endpoint * @param $data * @return \StdClass */ public function request($access_token, $endpoint, $data) { try { $wepay_object = new \WePay($access_token); return $wepay_object->request($endpoint, $data); } catch (\WePayRequestException $e) { return NULL; } }
public function payment() { $captcha = $this->f3->get('SESSION.captcha_qpay'); if ($this->f3->exists('POST.amount')) { if ($captcha && strtoupper($this->f3->get('POST.captcha_qpay')) != $captcha) { $this->f3->reroute('/home/Invalid CAPTCHA code'); } $amount = $this->f3->get('POST.amount'); $submit = $this->f3->get('POST.submit'); if ($submit == 'paypal') { $charge = $amount * 3.9 / 100; } if ($submit == 'credit') { $charge = $amount * 2.9 / 100; } if ($submit == 'bank') { $charge = $amount * 0.9 / 100; } $amount1 = $amount - $charge; $service_fee = 10; $vend_amount = round($amount1 * 41 - 10, 0); $this->f3->set('amount', $amount); $this->f3->set('charge', $charge); $this->f3->set('service_fee', $service_fee); $this->f3->set('vend_amount', $vend_amount, 60); $this->f3->set('meter', $this->f3->get('POST.meter'), 60); //set the session vairables $this->f3->set('SESSION.vend_amount', $vend_amount); $this->f3->set('SESSION.meter', $this->f3->get('POST.meter')); $client_id = "100047"; $client_secret = "dc6457521d"; $access_token = "STAGE_0340a90c4dcbf2101713e14fe5dec0acf509e8db983ab647e2e9a81de0b8ac37"; $account_id = "1443337002"; // you can find your account ID via list_accounts.php which users the /account/find call /** * Initialize the WePay SDK object */ //require '../../wepay/wepay.php'; Wepay::useStaging($client_id, $client_secret); $wepay = new WePay($access_token); /** * Make the API request to get the checkout_uri * */ try { $checkout = $wepay->request('/checkout/create', array('account_id' => $account_id, 'amount' => $amount, 'fee_payer' => "payee", 'short_description' => "this is a qpower payment", 'type' => "SERVICE", 'mode' => "iframe")); $this->f3->set('SESSION.checkout', $checkout); } catch (WePayException $e) { // if the API call returns an error, get the error message for display later $error = $e->getMessage(); $this->f3->set('error', $error); } $this->f3->set('checkout', $checkout); $this->f3->set('view', 'home.htm'); $this->f3->set('body', 'ajax-display.htm'); } }
function charge(&$order) { //create a code for the order if (empty($order->code)) { $order->code = $order->getRandomCode(); } //code to charge with gateway and test results would go here // application settings $account_id = pmpro_getOption('wepay_account_id'); $client_id = pmpro_getOption('wepay_client_id'); $client_secret = pmpro_getOption('wepay_client_secret'); $access_token = pmpro_getOption('wepay_access_token'); // credit card id to charge $credit_card_id = $order->wepay_token; //TODO: Make sure we're getting this // change to useProduction for live environments $environment = pmpro_getOption('gateway_environment'); if ($environment == 'live') { Wepay::useProduction($client_id, $client_secret); } else { Wepay::useStaging($client_id, $client_secret); } $wepay = new WePay($access_token); // charge the credit card $response = $wepay->request('checkout/create', array('account_id' => $account_id, 'amount' => '25.50', 'currency' => 'USD', 'short_description' => 'A vacation home rental', 'type' => 'goods', 'payment_method' => array('type' => 'credit_card', 'credit_card' => array('id' => $credit_card_id)))); //test response //simulate a successful charge $order->payment_transaction_id = "TEST" . $order->code; $order->updateStatus("success"); return true; }
$access_token = "STAGE_5dcc267978e11dfb927d91a5dd5f7ed1972484f30f59a64b3f30760ee7faf897"; Wepay::useStaging($client_id, $client_secret); $wepay = new WePay($access_token); /**************************************************/ if (isset($_REQUEST['refund_btn'])) { $chechout_id = $_REQUEST['refund_btn']; $refundtype = $_REQUEST['refundtype_' . $chechout_id]; $refund_amount = $_REQUEST['refund_amount_' . $chechout_id]; $refund_description = $_REQUEST['refund_description_' . $chechout_id]; $refund_arg = array('checkout_id' => $chechout_id, 'refund_reason' => $refund_description); if ($refundtype == 'partial') { $refund_arg['amount'] = $refund_amount; } //print_r($refund_arg); try { $refund_trs = $wepay->request('/checkout/refund', $refund_arg); //echo "<pre>"; // print_r($refund_trs); if ($refund_trs->state == "refunded" || $refund_trs->state == "captured") { ?> <div class="updated"><p><strong>Transaction Refunded Successfully</p></strong></div> <?php } } catch (WePayException $em) { // Something went wrong - normally you would log // this and give your user a more informative message // $em->getMessage(); ?> <div class="error"><p><strong><?php echo $em->getMessage(); ?>
<?php require './_shared.php'; ?> <h1>WePay Demo App: Open Account</h1> <a href="index.php">Back</a> <br /> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['account_name']) && isset($_POST['account_description'])) { try { $wepay = new WePay($_SESSION['wepay_access_token']); $account = $wepay->request('account/create', array('name' => $_POST['account_name'], 'description' => $_POST['account_description'])); // WePay sanitizes its own data, but displaying raw POST data on your own site is a XSS security hole. $name = htmlspecialchars($_POST['account_name']); $desc = htmlspecialchars($_POST['account_description']); $account_uri = htmlspecialchars($account->account_uri); echo "Created account {$name} for '{$desc}'! View on WePay at <a href=\"{$account_uri}\">{$account_uri}</a>. See all of your accounts <a href=\"accountlist.php\">here</a>."; } catch (WePayException $e) { // Something went wrong - normally you would log // this and give your user a more informative message echo $e->getMessage(); } } else { echo 'Account name and description are both required.'; } } ?> <form method="post">
require './_shared.php'; ?> <h1>WePay Demo App: Open Account</h1> <a href="index.php">Back</a> <br /> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['account_name']) && isset($_POST['account_description'])) { // WePay sanitizes its own data, but displaying raw POST data on your own site is a XSS security hole. $name = htmlentities($_POST['account_name']); $desc = htmlentities($_POST['account_description']); try { $wepay = new WePay($_SESSION['wepay_access_token']); $account = $wepay->request('account/create', array('name' => $name, 'description' => $desc)); echo "Created account {$name} for '{$desc}'! View on WePay at <a href=\"{$account->account_uri}\">{$account->account_uri}</a>. See all of your accounts <a href=\"accountlist.php\">here</a>."; } catch (WePayException $e) { // Something went wrong - normally you would log // this and give your user a more informative message echo $e->getMessage(); } } else { echo 'Account name and description are both required.'; } } ?> <form method="post"> <fieldset> <legend>Account Info</legend>
<?php require './_shared.php'; ?> <h1>WePay Demo App: User Info</h1> <a href="index.php">Back</a> <br /> <?php try { $wepay = new WePay($_SESSION['wepay_access_token']); $user = $wepay->request('user'); echo '<dl>'; foreach ($user as $key => $value) { echo "<dt>" . htmlspecialchars($key) . "</dt>"; echo "<dd>" . htmlspecialchars($value) . "</dd>"; } echo '</dl>'; } catch (WePayException $e) { // Something went wrong - normally you would log // this and give your user a more informative message echo $e->getMessage(); }
*/ $client_id = "PUT YOUR CLIENT_ID HERE"; $client_secret = "PUT YOUR CLIENT_SECRET HERE"; $access_token = "PUT YOUR ACCESS TOKEN HERE"; /** * Initialize the WePay SDK object */ require '../wepay.php'; Wepay::useStaging($client_id, $client_secret); $wepay = new WePay($access_token); /** * Make the API request to get a list of all accounts this user owns * */ try { $accounts = $wepay->request('/account/find'); } catch (WePayException $e) { // if the API call returns an error, get the error message for display later $error = $e->getMessage(); } ?> <html> <head> </head> <body> <h1>List all accounts:</h1> <p>The following is a list of all accounts that this user owns</p>
$client_secret = "PUT YOUR CLIENT_SECRET HERE"; $access_token = "PUT YOUR ACCESS TOKEN HERE"; $account_id = "PUT YOUR ACCOUNT_ID HERE"; // you can find your account ID via list_accounts.php which users the /account/find call /** * Initialize the WePay SDK object */ require '../wepay.php'; Wepay::useStaging($client_id, $client_secret); $wepay = new WePay($access_token); /** * Make the API request to get the checkout_uri * */ try { $checkout = $wepay->request('/checkout/create', array('account_id' => $account_id, 'amount' => 100, 'short_description' => "this is a test payment", 'type' => "GOODS", 'mode' => "iframe")); } catch (WePayException $e) { // if the API call returns an error, get the error message for display later $error = $e->getMessage(); } ?> <html> <head> </head> <body> <h1>Checkout:</h1> <p>The user will checkout here:</p>
/** * 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'); //make sure token is set at this point if (!isset($_SESSION['payment_method_id'])) { $mp->cart_checkout_error(__('The WePay Card Token was not generated correctly. Please go back and try again.', 'mp')); return false; } $order_id = $mp->generate_order_id(); //Get the WePay SDK require $mp->plugin_dir . 'plugins-gateway/wepay-files/wepay-sdk.php'; $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 if ($shipping_price = $mp->shipping_price()) { $total += $shipping_price; } //tax line if ($tax_price = $mp->tax_price()) { $total += $tax_price; } try { // Application settings $account_id = $this->account_id; $client_id = $this->client_id; $client_secret = $this->client_secret; $access_token = $this->access_token; // Credit card id to charge $credit_card_id = $_SESSION['payment_method_id']; if ($this->mode == 'staging') { WePay::useStaging($this->client_id, $this->client_secret); } else { WePay::useProduction($this->client_id, $this->client_secret); } $wepay = new WePay($access_token); // charge the credit card $response = $wepay->request('checkout/create', array('account_id' => $account_id, 'amount' => number_format($total, 2, '.', ''), 'currency' => 'USD', 'short_description' => $order_id, 'type' => $this->checkout_type, 'payment_method_id' => $credit_card_id, 'payment_method_type' => 'credit_card')); if (isset($response->state) && $response->state == 'authorized') { $credit_card_response = $wepay->request('/credit_card', array('client_id' => $this->client_id, 'client_secret' => $this->client_secret, 'credit_card_id' => $_SESSION['payment_method_id'])); //setup our payment details $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', 'mp'), $credit_card_response->credit_card_name); $payment_info['transaction_id'] = $order_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['payment_method_id']); $mp->set_cart_cookie(array()); } } catch (Exception $e) { unset($_SESSION['payment_method_id']); $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; } }
/** * @phutil-external-symbol class WePay */ public function processControllerRequest(PhortuneProviderController $controller, AphrontRequest $request) { $viewer = $request->getUser(); $cart = $controller->loadCart($request->getInt('cartID')); if (!$cart) { return new Aphront404Response(); } $cart_uri = '/phortune/cart/' . $cart->getID() . '/'; $root = dirname(phutil_get_library_root('phabricator')); require_once $root . '/externals/wepay/wepay.php'; WePay::useStaging($this->getWePayClientID(), $this->getWePayClientSecret()); $wepay = new WePay($this->getWePayAccessToken()); switch ($controller->getAction()) { case 'checkout': $return_uri = $this->getControllerURI('charge', array('cartID' => $cart->getID())); $cancel_uri = $this->getControllerURI('cancel', array('cartID' => $cart->getID())); $total_in_cents = $cart->getTotalPriceInCents(); $price = PhortuneCurrency::newFromUSDCents($total_in_cents); $params = array('account_id' => $this->getWePayAccountID(), 'short_description' => 'Services', 'type' => 'SERVICE', 'amount' => $price->formatBareValue(), 'long_description' => 'Services', 'reference_id' => $cart->getPHID(), 'app_fee' => 0, 'fee_payer' => 'Payee', 'redirect_uri' => $return_uri, 'fallback_uri' => $cancel_uri, 'auto_capture' => true, 'require_shipping' => 0, 'shipping_fee' => 0, 'charge_tax' => 0, 'mode' => 'regular', 'funding_sources' => 'bank,cc'); $result = $wepay->request('checkout/create', $params); // TODO: We must store "$result->checkout_id" on the Cart since the // user might not end up back here. Really this needs a bunch of junk. $uri = new PhutilURI($result->checkout_uri); return id(new AphrontRedirectResponse())->setIsExternal(true)->setURI($uri); case 'charge': $checkout_id = $request->getInt('checkout_id'); $params = array('checkout_id' => $checkout_id); $checkout = $wepay->request('checkout', $params); if ($checkout->reference_id != $cart->getPHID()) { throw new Exception(pht('Checkout reference ID does not match cart PHID!')); } switch ($checkout->state) { case 'authorized': case 'reserved': case 'captured': break; default: throw new Exception(pht('Checkout is in bad state "%s"!', $result->state)); } $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $charge = id(new PhortuneCharge())->setAmountInCents((int) $checkout->gross * 100)->setAccountPHID($cart->getAccount()->getPHID())->setAuthorPHID($viewer->getPHID())->setPaymentProviderKey($this->getProviderKey())->setCartPHID($cart->getPHID())->setStatus(PhortuneCharge::STATUS_CHARGING)->save(); $cart->openTransaction(); $charge->setStatus(PhortuneCharge::STATUS_CHARGED); $charge->save(); $cart->setStatus(PhortuneCart::STATUS_PURCHASED); $cart->save(); $cart->saveTransaction(); unset($unguarded); return id(new AphrontRedirectResponse())->setIsExternal(true)->setURI($cart_uri); case 'cancel': var_dump($_REQUEST); break; } throw new Exception("The rest of this isn't implemented yet."); }