Getting oxwall to submit a JSON document

98 views Asked by At

I am working on a billing plugin for oxwall. The lack of documentation is hell and I wonder why this is not a priority.

I have used the paypal and ccbill plugins as guides, and up till now things have been well, manageable.

Now, I need to submit the order to the gateway. For paypal and ccbill, they expect the details in a html POST. However, for this gateway (Paystack) the order detail has to be submitted as a JSON document, with an Authorization header...then a header redirect to the authorization_url.

I'd appreciate all the help.

1

There are 1 answers

0
Dayo On

Ok, I figured this out by 1. Taking advantage of a PHP library for the gateway...which supports guzzle and cURL as fallback. 2. calling the transaction initialize inside of form() See snippet below...

if ( $billingService->prepareSale($adapter, $sale) )
    {
        $totalAmount = floatval($sale->totalAmount * 100); //convert to kobo
        $saleHash = $sale->hash;
        $userEmail = $userService->findUserById($sale->userId)->getEmail();
        $metadata = array(
                'itemName' => $sale->entityDescription,
                'itemID' => $sale->entityKey,
        );

        $response = $paystack->transaction->initialize([
                'reference' => $saleHash,
                'amount' => $totalAmount, // in kobo
                'email' => $userEmail,
                'callback_url' => $fields['notify_url'],
                'metadata' => json_encode($metadata),
        ]);

        $url = $response->data->authorization_url;

        $masterPageFileDir = OW::getThemeManager()->getMasterPageTemplate('blank');
        OW::getDocument()->getMasterPage()->setTemplate($masterPageFileDir);

        header('Location: '.$url);

        $billingService->unsetSessionSale();

    }