Hallo Freunde,
ich brächte mal eure Hilfe, denn ich komme nicht weiter. Ich versuche ein Plugin zu erstellen, mit dem ich per PayPal.me bezahlen kann. Da die Seite nicht kommerziell ist, möchte ich payPal.me verwenden. Ist für unsere Zwecke vollkommen ausreichend. Dafür habe ich ein Plugin, welches zwei Dateien enthält. Beide liegen im gleichen Ordner. In der Kasse wird mir die Bezahloption angezeigt. Wenn ich jedoch auf Bestellen klicke, erhalte ich die Meldung "Fehler beim Bezahlvorgang. Versuche es bitte nochmal." Was muss ich ändern, damit es funktioniert?
Datei: paypal-gateway.php
PHP
<?php
/*
Plugin Name: PayPal ME Payment Gateway
Description: Ein einfaches Plugin für PayPal ME -Zahlungen.
Version: 1.65
Author: Marcus
*/
class PayPal_Gateway {
public function __construct() {
add_filter('woocommerce_payment_gateways', array($this, 'add_gateway'));
}
public function add_gateway($gateways) {
$gateways[] = 'WC_PayPal_Gateway';
return $gateways;
}
}
add_action('plugins_loaded', 'init_paypal_gateway');
function init_paypal_gateway() {
if (class_exists('WooCommerce')) {
require_once plugin_dir_path(__FILE__) . 'class-wc-paypal-gateway.php';
$paypal_gateway = new PayPal_Gateway();
}
}
?>
Alles anzeigen
Datei: class-wc-paypal-gateway.php
PHP
?php
// VERSION 1.65
class WC_PayPal_Gateway extends WC_Payment_Gateway {
public function __construct() {
$this->id = 'paypal';
$this->icon = apply_filters('woocommerce_paypal_icon', '');
$this->has_fields = false;
$this->method_title = __('PayPal', 'your-text-domain');
$this->method_description = __('Zahlung per PayPal', 'your-text-domain');
// Titel und Beschreibung aus den Einstellungen laden
$this->title = $this->get_option('title');
$this->description = $this->get_option('description');
// Gateway-Einstellungen und -Optionen
$this->init_form_fields();
$this->init_settings();
// Aktionen
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
}
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __('Aktivieren', 'your-text-domain'),
'type' => 'checkbox',
'label' => __('PayPal aktivieren', 'your-text-domain'),
'default' => 'yes',
),
'title' => array(
'title' => __('Titel', 'your-text-domain'),
'type' => 'text',
'description' => __('Dieser Titel wird im Checkout angezeigt.', 'your-text-domain'),
'default' => __('PayPal.Me', 'your-text-domain'),
),
'description' => array(
'title' => __('Beschreibung', 'your-text-domain'),
'type' => 'textarea',
'description' => __('Optionale Beschreibung der Zahlungsmethode.', 'your-text-domain'),
'default' => __('Bezahlen Sie mit PayPal.Me.', 'your-text-domain'),
),
// Weitere Einstellungen hier hinzufügen
);
}
public function process_payment($order_id) {
// Logik für die Zahlungsverarbeitung
// Verwenden des PayPal-Me-URL und den Kassenbetrag
if (!is_ajax()) {
$order = wc_get_order($order_id);
// Zahlung abschließen und Bestellung als "bezahlt" markieren
$order->payment_complete();
// Gesamtbetrag aus der Bestellung erhalten
$total_amount = $order->get_total();
error_log(print_r($total_amount, true));
// PayPal.Me-Link mit Gesamtbetrag
$paypal_me_link = 'https://paypal.me/meinName/' . rawurlencode($total_amount);
// Hier den Benutzer auf die Checkout-Seite weiterleiten
return array(
'result' => 'success',
'redirect' => wc_get_checkout_url(),
);
}
}
}
?>
Alles anzeigen
Vielen Dank schon mal im vorraus für eure Hilfe.
Gruß
Marcus