Payment method

Phoca Cart - complex e-commerce extension
User avatar
landed
Phoca Professional
Phoca Professional
Posts: 171
Joined: 15 Sep 2023, 10:51

Payment method

Post by landed »

I have been using AI to code very successfully in Joomla and wish to see if I can also do this for payment options? I haven't seen any plugins and can't find where these files would be. Is this something anyone could help me with?
User avatar
Nidzo
Phoca Professional
Phoca Professional
Posts: 472
Joined: 07 Nov 2018, 14:55

Re: Payment method

Post by Nidzo »

For payments you need to develop Phoca Cart payment plugin. Here are some free https://www.phoca.cz/download/99-phoca- ... rt-plugins
For payment gateways like Stripe, Molie etc. there are paid third party plugins or you can try to develop your own.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49007
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Payment method

Post by Jan »

The basic payment method like PayPal can be found in main package, so you can inspire there.

See:
https://www.phoca.cz/phocacart-extensio ... =1-payment

for list of different payment methods for Phoca Cart.

Jan
If you find Phoca extensions useful, please support the project
User avatar
landed
Phoca Professional
Phoca Professional
Posts: 171
Joined: 15 Sep 2023, 10:51

Re: Payment method

Post by landed »

I couldn't find where it is, can you pass me the folder location please? I'd rather pay you 49 euros per year than a 3rd party for a payment option.
User avatar
Benno
Phoca Hero
Phoca Hero
Posts: 9866
Joined: 04 Dec 2008, 11:58
Location: Germany
Contact:

Re: Payment method

Post by Benno »

Hi,
download Phoca Cart v5.2.0 Package.
Unzip it local on your PC --> Click on 'packages' folder and unzip 'plg_pcp_paypal_standard_v5.1.1.zip'
This is the basic Phoca Cart payment plugin PayPal.

Kind regards,
Benno
User avatar
landed
Phoca Professional
Phoca Professional
Posts: 171
Joined: 15 Sep 2023, 10:51

Re: Payment method

Post by landed »

Thank You
User avatar
Benno
Phoca Hero
Phoca Hero
Posts: 9866
Joined: 04 Dec 2008, 11:58
Location: Germany
Contact:

Re: Payment method

Post by Benno »

You're welcome!

Kind regards,
Benno
User avatar
landed
Phoca Professional
Phoca Professional
Posts: 171
Joined: 15 Sep 2023, 10:51

Re: Payment method

Post by landed »

Is there anything special which PhocaCart is doing as my plugin function is not firing:onPCPbeforeSetPaymentForm.
I created it very much the same way as the Paypal standard. Is there any gotcha which I need to know about. Thanks.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49007
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Payment method

Post by Jan »

Hi, first of all you need to detect if the plugin is active at all. Print some debug info in the event. Check if the plugin is installed, active and assigned to selected payment method, then try to print some debug and exit the code in the plugin to see if it is active.

If not installed try to use n3t debug, which will display you important information when debugging: https://n3t.bitbucket.io/extension/n3t-debug/

Jan
If you find Phoca extensions useful, please support the project
User avatar
landed
Phoca Professional
Phoca Professional
Posts: 171
Joined: 15 Sep 2023, 10:51

Re: Payment method

Post by landed »

Yes it installs and can be selected in checkout, there is no redirect however to input payment. So the checkout finishes without needing to insert card information. In backend shows pending. There is no debug run.

<?php
/**
* @package Joomla.Plugin
* @subpackage Pcp.Stripe_Standard
* @copyright (C) 2025
* @license GNU/GPL
*/

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Uri\Uri;

require_once JPATH_SITE . '/plugins/pcp/stripe_standard/helpers/webhooklistener.php';

class plgPCPStripe_Standard extends CMSPlugin
{
protected $name = 'stripe_standard';

public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
$this->loadLanguage();
}

/**
* Build the form that redirects/calls Stripe Checkout
*/
public function onPCPbeforeSetPaymentForm(&$form, $paramsC, $params, $order, $eventData)
{
if (!isset($eventData['pluginname']) || $eventData['pluginname'] !== $this->name) {
return false;
}

$publishableKey = $params->get('publishable_key', '');
$secretKey = $params->get('secret_key', '');
$sandbox = (int) $params->get('sandbox', 1);

if (!$publishableKey || !$secretKey) {
throw new \RuntimeException('Stripe keys not configured.');
}

// Load Stripe SDK (installed by composer)
\Stripe\Stripe::setApiKey($secretKey);

// Create Stripe Checkout Session
try {
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => strtolower($order['common']->currency_code),
'product_data' => [
'name' => Text::_('COM_PHOCACART_ORDER') . ': ' . $order['common']->order_number,
],
'unit_amount' => (int) round($order['total'][count($order['total']) - 1]->amount * 100), // in cents
],
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => Uri::root(false) . 'index.php?option=com_phocacart&view=response&task=response.paymentrecieve&type=stripe_standard&oid=' . (int) $order['common']->id,
'cancel_url' => Uri::root(false) . 'index.php?option=com_phocacart&view=response&task=response.paymentcancel&type=stripe_standard&oid=' . (int) $order['common']->id,
'metadata' => [
'order_id' => (int) $order['common']->id,
],
]);
} catch (\Exception $e) {
throw new \RuntimeException('Stripe error: ' . $e->getMessage());
}

// Render form / redirect script
$form = '<script src="https://js.stripe.com/v3/"></script>
<script>
var stripe = Stripe("' . htmlspecialchars($publishableKey, ENT_QUOTES, 'UTF-8') . '");
stripe.redirectToCheckout({ sessionId: "' . $session->id . '" });
</script>';

return true;
}

/**
* Called when PhocaCart wants to validate payment notification (webhook style)
*/
public function onPCPbeforeCheckPayment($pid, $eventData)
{
if (!isset($eventData['pluginname']) || $eventData['pluginname'] !== $this->name) {
return false;
}

// Load listener
if (!class_exists('PhocacartStripeWebhookListener')) {
require_once(JPATH_SITE . '/plugins/pcp/stripe_standard/helpers/webhooklistener.php');
}

$paymentTemp = new PhocacartPayment();
$paymentOTemp = $paymentTemp->getPaymentMethod((int) $pid);
$paramsPaymentTemp = $paymentOTemp->params;

$listener = new PhocacartStripeWebhookListener($paramsPaymentTemp);
return $listener->handle();
}
}
Post Reply