app/Dorcas/Support/helpers.php
/**
 * Verifies a Paystack transaction information, and returns a transaction object that can be saved to the database.
 *
 * @param string            $secretKey
 * @param string            $reference
 * @param Order $order
 *
 * @return array
 * @throws HttpException
 * @throws UnexpectedValueException
 * @throws Exception
 */
Verifies a Paystack transaction information, and returns a transaction object that can be saved to the database.


Verifies a Paystack transaction information and returns a transaction object that can be saved to the database .
function payment_verify_paystack(string $secretKey, string $reference, Order $order)
{
    $paystack = new Paystack($secretKey);
    $response = $paystack->transaction->verify(['reference' => $reference]);
    if (!$response->status) {
        throw new \HttpException($response->message);
    }
    if ($order->id !== $response->data->metadata->cart_id) {
        throw new UnexpectedValueException('We could not verify that the transaction is for your current order.');
    }
    return [
        'channel' => 'paystack',
        'reference' => $reference,
        'amount' => $response->data->amount / 100,
        'response_code' => $response->data->status === 'success' ? '00' : 'EE',
        'response_description' => $response->data->gateway_response,
        'json_payload' => [
            'transaction_date' => $response->data->transaction_date,
            'fee' => ($response->data->fees / 100),
            'card' => [
                'last4' => $response->data->authorization->last4,
                'exp_month' => $response->data->authorization->exp_month,
                'exp_year' => $response->data->authorization->exp_year,
                'channel' => $response->data->authorization->channel,
            ]
        ],
        'is_successful' => $response->data->status === 'success'
    ];
}
function payment_verify_paystack ( string $ secretKey , string $ reference , Order $ order ) { $ paystack = new Paystack ( $ secretKey ) ; $ response = $ paystack -> transaction -> verify ( [ 'reference' => $ reference ] ) ; if ( ! $ response -> status ) { throw new \ HttpException ( $ response -> message ) ; } if ( $ order -> id !== $ response -> data -> metadata -> cart_id ) { throw new UnexpectedValueException ( 'We could not verify that the transaction is for your current order.' ) ; } return [ 'channel' => 'paystack' , 'reference' => $ reference , 'amount' => $ response -> data -> amount / 100 , 'response_code' => $ response -> data -> status === 'success' ? '00' : 'EE' , 'response_description' => $ response -> data -> gateway_response , 'json_payload' => [ 'transaction_date' => $ response -> data -> transaction_date , 'fee' => ( $ response -> data -> fees / 100 ) , 'card' => [ 'last4' => $ response -> data -> authorization -> last4 , 'exp_month' => $ response -> data -> authorization -> exp_month , 'exp_year' => $ response -> data -> authorization -> exp_year , 'channel' => $ response -> data -> authorization -> channel , ] ] , 'is_successful' => $ response -> data -> status === 'success' ] ; }
Verifies a Paystack transaction information, and returns a transaction object that can be saved to the database.
Verifies a Paystack transaction information and returns a transaction object that can be saved to the database .