Метод оплаты «Привязка к действию» под названием «Swish» с openposPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Метод оплаты «Привязка к действию» под названием «Swish» с openpos

Сообщение Anonymous »

Мне нужно подключить qr-код для обработки платежей в POS-системе Wordpress под названием «openpos». Пожалуйста, мне нужна помощь.

Код: Выделить всё

add_action('op_add_order_after', function($order,$order_data){
// do your action at here
});
Взмах

Код: Выделить всё

add_action('plugins_loaded', 'init_woocommerce_swish_gateway', 0);
function init_woocommerce_swish_gateway() {

if ( ! class_exists( 'WC_Payment_Gateway' ) ) return;
define( 'REDLIGHT_SM_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
define( 'REDLIGHT_SM_PLUGIN_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) );
define( 'REDLIGHT_SM_STORE_URL', 'https://redlight.se' );
define( 'REDLIGHT_SM_ITEM_NAME', 'woocommerce-gateway-swish' );
define( 'REDLIGHT_SM_ITEM_ID', '35705' );
define( 'REDLIGHT_SM_VERSION', '3.2.0' );

if( !class_exists( 'Swish_QR' ) ) {
include( dirname( __FILE__ ) . '/includes/class-wc-gateway-swish-qr.php' );
}
function redlight_swish_plugin_updater() {
// retrieve our license key from the DB
$license = get_option( 'woocommerce_redlight_swish_settings');
$license_key = $license['redlight_license_key'];
// setup the updater

if( !class_exists( 'License_WP_Plugin_Updater' ) ) {
// load our custom updater
include_once REDLIGHT_SM_PLUGIN_PATH . '/includes/License_WP_Plugin_Updater.php';
}
// setup the updater
$license_wp_updater = new License_WP_Plugin_Updater( REDLIGHT_SM_STORE_URL, __FILE__,
array(
'version' => REDLIGHT_SM_VERSION,      // current version number
'license' => $license_key,             // license key (used get_option above to retrieve from DB)
'item_slug' => REDLIGHT_SM_ITEM_NAME,      // Slug of the product
'item_id' => REDLIGHT_SM_ITEM_ID,      // ID of the product
'beta'    => false,
)
);
}
add_action( 'admin_init', 'redlight_swish_plugin_updater', 0 );
function redlight_swish_activate_license() {

// listen for our activate button to be clicked
if( isset( $_POST['woocommerce_redlight_swish_redlight_license_key'] ) ) {
// retrieve the license from the database
$license = get_option( 'woocommerce_redlight_swish_settings');
$license = trim($license['redlight_license_key']);

$api_params = array(
'wc-api'         =>'license_wp_api_activation',
'request'        => 'activate',
'license_key'    => $license,
'api_product_id' => urlencode( REDLIGHT_SM_ITEM_NAME ), // Plugin slug from licence-wp,
'instance'       => str_replace( array( 'http://', 'https://' ), '', trim( home_url() ) ),
);
$response = wp_remote_get(
REDLIGHT_SM_STORE_URL. '?' .  http_build_query( $api_params, '', '&' ),
array(
'timeout' => 15,
'headers'   => array(
'Accept' => 'application/json'
)
)
);

// make sure the response came back okay
if ( is_wp_error( $response ) )
return false;

$license_value = '';
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
if ( false === $license_data->success ) {
$license_value = 'invalid';
}elseif( $license_data->success ){
$license_value = 'valid';
}

// $license_data->license will be either "valid" or "invalid"

update_option( 'redlight_license_status', $license_value );

}
}
add_action('admin_init', 'redlight_swish_activate_license');
function redlight_swish_deactivate_license() {
// listen for our activate button to be clicked
if( isset( $_POST['woocommerce_redlight_swish_redlight_license_deactivate'] ) ) {

// retrieve the license from the database
$license = get_option( 'woocommerce_redlight_swish_settings');
$license = trim($license['redlight_license_key']);

$api_params = array(
'wc-api'         =>'license_wp_api_activation',
'request'        => 'deactivate',
'license_key'    => $license,
'api_product_id' => urlencode( REDLIGHT_SM_ITEM_NAME ), // Plugin slug from licence-wp,
'instance'       => str_replace( array( 'http://', 'https://' ), '', trim( home_url() ) ),
);

$response = wp_remote_get(
REDLIGHT_SM_STORE_URL. '?' . http_build_query( $api_params, '', '&' ),
array(
'timeout' => 15,
'headers'   => array(
'Accept' => 'application/json'
)
)
);

// make sure the response came back okay
if ( is_wp_error( $response ) )
return false;

// decode the license data
$license_data = json_decode( wp_remote_retrieve_body( $response ) );

// $license_data->license will be either "deactivated" or "failed"
if( $license_data->success )
delete_option( 'redlight_license_status' );

}
}
add_action('admin_init', 'redlight_swish_deactivate_license');
// Localisation
load_plugin_textdomain('redlight-swish', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');

add_filter('woocommerce_payment_gateways', 'add_woocommerce_swish_gateway' );

/*
Initiate the WooCommerce_Swish class.
This used to be in a separate file, but it caused a headers already sent warning.
*/

class WooCommerce_Swish extends WC_Payment_Gateway {

/**
* Construct. Setup the woocommerce gateway settings and initate needed hooks.
*
* @access public
* @return void
*/

function __construct() {

$this->id = "redlight_swish";

// The Title shown on the top of the Payment Gateways Page next to all the other Payment Gateways
$this->method_title = "Swish";

// The description for this Payment Gateway, shown on the actual Payment options page on the backend
$this->method_description = __( "Extends WooCommerce. Provides a [url=http://www.getswish.se]Swish[/url] gateway for WooCommerce.", 'redlight-swish' );

$this->title = __( "Swish", 'redlight-swish' );

// If you want to show an image next to the gateway's name on the frontend, enter a URL to an image.
$this->icon = plugins_url( 'assets/images/swish_logo.png', __FILE__ );
$this->swishimglogo = plugins_url( 'assets/images/Swish-logo-image-vert.png', __FILE__ );
$this->swishtextlogo = plugins_url( 'assets/images/Swish-logo-text-vert.png', __FILE__ );

// Bool.  Can be set to true if you want payment fields to show on the checkout
// if doing a direct integration, which we are doing in this case
$this->has_fields = true;

// This basically defines your settings which are then loaded with init_settings()
$this->init_form_fields();

// After init_settings() is called, you can get the settings and load them into variables, e.g:
$this->init_settings();
$this->supports = array(
'products'
);

// Turn these settings into variables we can use
foreach ( $this->settings as $setting_key => $value ) {
$this->$setting_key = $value;
}

// Actions
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
add_action( 'woocommerce_thankyou_'.$this->id, array( $this, 'thankyou_page' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_styles' ) );

// Customer Emails
add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
//Filters
add_filter( 'woocommerce_settings_api_sanitized_fields_' . $this->id, array( $this, 'sanitize_settings' ) );

}

public function register_plugin_styles() {
wp_register_style( 'swish-css', plugins_url( 'woocommerce-gateway-swish/assets/css/swish.css' ) );
wp_enqueue_style( 'swish-css' );
}
/**
* Build the administration fields for the gateway.
*
* @access public
* @return void
*/

public function init_form_fields() {
$this->form_fields = array(
'redlight_license_key' => array(
'title'     => __( 'License key', 'redlight-swish' ),
'type'      => 'text',
'description'   => __( 'To enable updates for this plugin, enter the license key you recived when you downloeded this plugin', 'redlight-swish' ),
),
'redlight_license_deactivate' => array(
'label'     => __( 'Deactivate License key', 'redlight-swish' ),
'type'      => 'checkbox',
'default'   => 'no',
'description'   => __( 'Deactivating this license key will disable updates', 'redlight-swish' ),
),
'enabled' => array(
'title'     => __( 'Enable / Disable', 'redlight-swish' ),
'label'     => __( 'Enable this payment gateway', 'redlight-swish' ),
'type'      => 'checkbox',
'default'   => 'no',
),
'title' => array(
'title'     => __( 'Title', 'redlight-swish' ),
'type'      => 'text',
'desc_tip'  => __( 'Enter the name you want displayed for the user.', 'redlight-swish' ),
'default'   => __( 'Swish', 'redlight-swish' ),
),
'description' => array(
'title'     => __( 'Description', 'redlight-swish' ),
'type'      => 'textarea',
'desc_tip'  => __( 'Pay your purchase directly through your smartphone with Swish payment app that is available for both iPhone and Android.
Note that you must have your mobile phone and log-in information ready to complete the purchase .
Payment will be registred directly and the money will be reserved from your account.  No extra fee is charged .',
'redlight-swish' ),
'default'   => __( 'Swish works between  Danske Bank,  Handelsbanken,  ICA Banken,  Länsförsäkringar,  Nordea,  SEB,  Skandia,  Sparbanken Syd,  Sparbanken Öresund samt Swedbank och Sparbankerna.', 'redlight-swish' ),
'desc_tip'    => true,
),
'message' => array(
'title'       => __( 'Message', 'redlight-swish' ),
'type'        => 'textarea',
'description' => __( 'Instructions that will appear on the "Thank you for your order " and the e-mail message.', 'redlight-swish' ),
'default'     => __( 'Since payments made ​​via Swish must be manually reviewed and matched against your order as it can take up to 24 hours before it is done. You get an email when your order is processed.', 'redlight-swish' ),
'desc_tip'    => true,
),
'swish_number' => array(
'title'     => __( 'Your Swish number', 'redlight-swish' ),
'type'      => 'text',
'description' => __( 'Enter the number you received when you joined Swish .', 'redlight-swish' ),
),
'show_desc' => array(
'title'     => __( 'Show / Hide description', 'redlight-swish' ),
'label'     => __( 'Show description', 'redlight-swish' ),
'type'      => 'checkbox',
'default'   => 'no',
),
'swish_number_desc' => array(
'title'       => __( 'Description of your Swish account', 'redlight-swish' ),
'type'        => 'textarea',
'description' => __( 'Example: Company Inc', 'redlight-swish' ),
'default'     => '',
'desc_tip'    => true,
),
'swish_number_two' => array(
'title'     => __( 'Your second Swish number', 'redlight-swish' ),
'type'      => 'text',
'description' => __( 'If you have more than one Swish number , enter the second here.  If not, leave blank', 'redlight-swish' ),
),
'show_desc_two' => array(
'title'     => __( 'Show / Hide description', 'redlight-swish' ),
'label'     => __( 'Show description', 'redlight-swish' ),
'type'      => 'checkbox',
'default'   => 'no',
),
'swish_number_desc_two' => array(
'title'       => __( 'Description of your second Swish account', 'redlight-swish' ),
'type'        => 'textarea',
'description' => __( 'Example: Company Two Inc', 'redlight-swish' ),
'default'     => '',
'desc_tip'    => true,
),
'show_qr_code' => array(
'title'     => __( 'Activate / Deactivate QR-code', 'redlight-swish' ),
'label'     => __( 'Show Swish QR-code at thank-you page', 'redlight-swish' ),
'type'      => 'checkbox',
'default'   => 'yes',
'description'   => __( 'This requires you to have a valid Swish agreement for Swish-företag', 'redlight-swish' ),
),
'show_payment_details_in_email' => array(
'title'     => __( 'Show payment details in email', 'redlight-swish' ),
'label'     => __( 'Show payment details in email', 'redlight-swish' ),
'type'      => 'checkbox',
'default'   => 'yes',
'description'   => '',
),
'qr_code_editnr' => array(
'title'     => __( 'Allow customer to make changes to the Swish-nr', 'redlight-swish' ),
'label'     => __( '', 'redlight-swish' ),
'type'      => 'checkbox',
'default'   => 'no',
'description'   => __( 'This will allow the customer to edit the number after qr-code is scanned', 'redlight-swish' ),
),
'qr_code_editamount' => array(
'title'     => __( 'Allow customer to make changes to the amount', 'redlight-swish' ),
'label'     => __( '', 'redlight-swish' ),
'type'      => 'checkbox',
'default'   => 'no',
'description'   => __( 'This will allow the customer to edit the amount after qr-code is scanned', 'redlight-swish' ),
),
);
}
/**
* Sanitize our settings
*/
function sanitize_settings( $new ) {
$old = $this->redlight_license_key;
if( $old && $old != $new['redlight_license_key'] ) {
delete_option( 'redlight_license_status' ); // new license has been entered, so must reactivate
}
return $new;
}

/**
* Output the "order received"-page.
*
* @access public
* @param int $order_id
* @return void
*/

public function thankyou_page( $order_id ) {
$this->swish_details( $order_id );
}

/**
* Add content to the WC emails.
*
* @access public
* @param WC_Order $order
* @param bool $sent_to_admin
* @param bool $plain_text
* @return void
*/

public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
if ( ! $sent_to_admin && 'redlight_swish' === $order->get_payment_method() &&  $order->has_status( 'on-hold' ) ) {
$this->swish_email_details( $order->get_id() );
}

}

/**
* Get bank details and place into a list format.
*
* @access private
* @param string $order_id (default: '')
* @return void
*/

private function swish_details( $order_id = '' ) {

if ( empty( $this->swish_number ) ) {
return;
}

$order = new WC_Order($order_id);
//Load Swish CSS
wp_enqueue_style('swish');
if($this->show_qr_code == "yes"){
if($this->qr_code_editnr == "yes"){
$editnumber = true;
}else{
$editnumber = false;
}
if($this->qr_code_editamount == "yes"){
$editamount = true;
}else{
$editamount = false;
}
$data =
[
'format' => 'svg',
'payee'  => [
'value' => $this->swish_number,
'editable'=> $editnumber
],
'amount' => [
'value' => floatval($order->get_total()),
'editable'=> $editamount
],
'message' => [
"value" => sprintf( __( "Payment for order %s", 'redlight-swish' ), $order->get_order_number() )
],
'size' => 600,
'border' => 1,
'transparent' => true
];
$data_string = json_encode($data);
$swishQR = Swish_QR::generateQR($data_string);
}

?>

[img]" />
[img]" />



Подробнее здесь: [url]https://stackoverflow.com/questions/78170119/hook-to-action-payment-method-called-swish-with-openpos[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»