Payment Extensions

The Sitemagic Payment Standard extension includes two Payment Extensions for international PayPal and Danish Ewire. Writing applications consuming the functionality of these Payment Extensions is very easy.

The following examples will demonstrate the use of the Payment Extension Manager, and how payments are carried through using a Payment Extension.


Get list of Payment Extensions available

// Make payment functionality available to extension
SMExtensionManager::Import("SMPayment", "SMPayment.classes.php", true);

class MyWebshopExtension extends SMExtension
{
    public function Render()
    {
        $paymentExtensionManager = SMPaymentExtensionManager::GetInstance();
        $paymentExtensions = $paymentExtensionManager->GetExtensions();

        return implode(", ", $paymentExtensions); // returns: SMEwire, SMPayPal
    }
}
Carry out payment using Payment Extension (during PreRender)

The example below is based on the Checkout approach, which will open a "payment window", allowing the payment provider to take care of the entire payment process. All we have to do is provide a unique order ID, the currency, and the amount to charge (in the smallest unit available).

Get a list of supported currencies by invoking the GetCurrencies() function on the Payment Extension ($paypal below).
PayPal - currencies supported: EUR, DKK, USD, SEK, NOK, GBP
Ewire - currencies supported: DKK

The amount is immediately captured (transfered) from the visitors account to your account.

// Make payment functionality available to extension
SMExtensionManager::Import("SMPayment", "SMPayment.classes.php", true);

class MyWebshopExtension extends SMExtension
{
    public function PreRender()
    {
        $paymentExtensionManager = SMPaymentExtensionManager::GetInstance();
        $paypal = $paymentExtensionManager->CreatePaymentInstance("SMPayPal", $this->context);

        // This will override all content within the website by loading PayPal instead.
        // PayPal will charge 5 USD from the visitors PayPal account. The payment will
        // be displayed within your PayPal account with the UniqueOrderId as the title.

        $paypal->RegisterExternalCheckout("UniqueOrderId, "USD", 500);
    }
}
The same approach is used with the Ewire Payment Extension. Simply replace "SMPayPal" with "SMEwire" when invoking the CreatePaymentInstance function.

Not all Payment Extensions provide the same functionality. Supported functionality is revealed by invoking the GetSupportedFunctions function on the Payment Extension ($paypal->GetSupportedFunctions()).


PayPal specific functionality

The PayPal extension supports more functionality than the Ewire extension. The extension is capable of handling notifications from PayPal, which are sent when payments are received or when changes are made to the payment (ie some of the amount is returned). The status of a payment may also be queried. This is all described in greater details in the Sitemagic Payment Standard documentation.


Functionality to come

We have yet to implement support for all the great API functionality in PayPal, allowing you to create your own "payment window", use manual captures, create subscriptions etc. This will most likely be added in a future version of the PayPal Payment Extension. However, the Sitemagic Payment Standard is very well though through, and creating a new Payment Extension capable of being consumed by any extension, should now be a breeze.