0

I am trying to build a payment plugin for Joomdonation Documents Seller. I can send an order to a Bank and pay, but after that I am having a problem.

When an order is created and sent, it has status: in_progress, after the payment status changes to success, I try to change the record in database with if ($status == success) but this fails.

Here are both files:

Start payment

session_start();

defined('_JEXEC') or die;

class os_bog extends DSFPayment
{
    public function __construct($params, $config = [])
    {
        parent::__construct($params, $config);
    }

    public function processPayment($row, $data)
    {
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => 'https://ipay.ge/opay/api/v1/oauth2/token',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => 'grant_type=client_credentials',
            CURLOPT_HTTPHEADER =>array('Content-Type: application/x-www-form-urlencoded','Authorization: Basic '. base64_encode($client_id.':'.$secret_key)),
        ));
    
        $response = curl_exec($curl);
        curl_close($curl);
        $response = json_decode($response, true);
        $token = $response ['access_token'];
        
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => 'https://ipay.ge/opay/api/v1/checkout/orders',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS =>'{
                "intent": "CAPTURE",
                "items": [
                    {
                      "amount": "'. $data['amount'].'" ,
                      "description":  "'.$data['item_name'].'",        
                      "product_id": "'.$data['item_name'].'"
                    }
                ],
                "locale": "ka",
                "redirect_url": "https://editor.ge/",
                "shop_order_id": "'. $data['order_number'].'",
                "show_shop_order_id_on_extract": false ,
                "capture_method": "AUTOMATIC",
                "purchase_units": [
                    {
                        "amount": {
                            "currency_code": "GEL",
                            "value": "'. $data['amount'].'"  
                        }
                    }
                ]
            }',
            CURLOPT_HTTPHEADER => array(
                'Content-Type:  application/json',
                'Authorization: Bearer' . $token
            ),
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $response = json_decode($response, true);
    
        $payment_hash = $response ['payment_hash'];
        $order_id = $response ['order_id'];
    
        if (isset($response['order_id'])) {
            $payment_hash = $response['payment_hash'];
            $order_id = $response['order_id'];
            $redirect_url = $response['links'][1]['href'];
           header("Location:" . $redirect_url);
        }   
        $_SESSION['order_data'] = array(
            'order_id' => $response ['order_id'],
            'payment_hash' => $response ['payment_hash'],
        );      
        return $response;
    }

    public function verifyPayment()
    {
        if ($this->validate())
        {
            
        }
    }

    protected function validate()
    {
        $this->notificationData = $_REQUEST;
        return true;
    }   
}

Check status of payment

session_start();
    
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://ipay.ge/opay/api/v1/oauth2/token',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => 'grant_type=client_credentials',
    CURLOPT_HTTPHEADER =>array('Content-Type: application/x-www-form-urlencoded','Authorization: Basic '. base64_encode($client_id.':'.$secret_key)),
));
$response = curl_exec($curl);

curl_close($curl);
$response = json_decode($response, true);
$token = $response ['access_token'];
$order_data = ($_SESSION['order_data']);
$order_id = $order_data['order_id'];
$payment_hash = $order_data['payment_hash'];
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://ipay.ge/opay/api/v1/checkout/payment/'.$order_id,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_HTTPHEADER => array(
    'Content-Type:  application/json',
    'Authorization: Bearer' . $token  ),
));

$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response, true);
$status = $response ['status'];

p.s. I can not check payment inside the plugin(first code), callback url is predefined by the Bank and I was not able to put code inside public function verifyPayment()

Could someone help?

2
  • 1
    This might not be resolving advice, but I am noticing that you are manually crafting the json string in the CURLOPT_POSTFIELDS value. You should never craft your own json string manually. You should build an array, then for CURLOPT_POSTFIELDS you can either pass in a json_encode() or http_build_query() string.
    – mickmackusa
    Feb 2, 2022 at 22:02
  • 1
    thank you, will change this part Feb 3, 2022 at 4:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.