File: /www/sites/sofakasa.com/index/wp-content/plugins/ppcard/includes/gateways/card.php
<?php
namespace PPCard\GateWays;
use WC_Payment_Gateway;
if (!defined('ABSPATH')) {
exit;
}
class Card extends WC_Payment_Gateway
{
use GateWayTrait;
const GATEWAY_ID = 'card';
const PAY_WITH = 'ppcard';
const ROUTE_SLUG_ASYNC_INTENT = 'card_async';
const ROUTE_SLUG_WEBHOOK = 'ppcard_webhook';
const ROUTE_SLUG_AJAX = 'ppcard_ajax';
const PLUGIN_VERSION_ID = 'ppcard';
const PLUGIN_FIELDS_TITLE = 'Pay With Card';
const PLUGIN_VERSION = 'v1.2.0';
const PAYMENT_MESSAGE = 'PPCard payment processing';
const GATEWAY_URL = PPCARD_GATEWAY_VERSION . '/api/jssdk/orders';
private $retry = 3;
private $sleep = 500 * 500;
public $method_title = 'Card';
public $title = 'Card';
public $id = self::GATEWAY_ID;
public $has_fields = false;
public function __construct()
{
$this->init_settings();
$this->method_description = __('Accept only credit and debit card payments with your card account.', PPCARD_PLUGIN_NAME);
$this->form_fields = $this->get_form_fields();
$this->title = $this->get_option('title');
$this->icon = PPCARD_PLUGIN_URL . '/assets/images/ppcard.png';
add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'process_admin_options']);
}
public function payment_fields() // @codingStandardsIgnoreLine
{
if ($this->get_option('checkout_form_type') === 'inline') {
echo '<p>' . $this->description . '</p>';
echo '<div id="ppcard-card"></div>';
} else {
parent::payment_fields();
}
}
public function process_payment($orderId) // @codingStandardsIgnoreLine
{
$order = wc_get_order($orderId);
$order->update_status('pending');
WC()->session->set('card_order_id', $orderId);
wc_reduce_stock_levels($orderId);
return array(
'result' => 'success',
'messages' => '<div class="woocommerce-message">' . self::PAYMENT_MESSAGE . '</div>',
);
}
public function get_form_fields() // @codingStandardsIgnoreLine
{
return apply_filters(
'wc_ppcard_setting',
$this->getFormFields()
);
}
public static function get_async_intent_url() // @codingStandardsIgnoreLine
{
if( absint(get_query_var('order-pay')) ) {
WC()->session->set('card_order_id', absint(get_query_var('order-pay')));
}
return WC()->api_request_url(self::ROUTE_SLUG_ASYNC_INTENT);
}
public function getVersion()
{
return self::PLUGIN_VERSION;
}
public function getWebhookSignUrl()
{
return $this->getRelativePath(WC()->api_request_url(self::ROUTE_SLUG_WEBHOOK));
}
public function checkout()
{
$orderId = WC()->session->get('card_order_id');
$order = wc_get_order($orderId);
if($order->get_payment_method() !== $this->id) {
$order->set_payment_method( $this->id );
$order->save();
}
$this->createOrder($this->buildCreateOrderBody($orderId), $orderId);
}
public function submit($result)
{
$bizId = $result['data']['biz_id'];
$data = array(
'biz_id' => $bizId,
'client_info' => $result['client_info'],
'order_id' => $result['order_id'],
'a_site' => urlencode($result['a_site']),
'b_site' => urlencode($result['b_site']),
'c_site' => $result['data']['c_site'],
'redirect_url' => urlencode($result['redirect_url']),
'sk' => urlencode($result['sk']),
);
$cSiteUrl = $data['c_site'] . '/' . self::PAY_WITH . '/modules/process-js.php?biz_id=' . $bizId . '&sk=' . $data['sk']
. '&a_site=' . $data['a_site'] . '&b_site=' . $data['b_site'] . '&redirect_url=' . $data['redirect_url'] . '&last=0';
echo json_encode(['code' => '200', 'url' => $cSiteUrl]);
die;
}
}