PHP code example of dlds / yii2-payment

1. Go to this page and download the library: Download dlds/yii2-payment library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dlds / yii2-payment example snippets


class MyPaymentHandler extends \dlds\payment\PaymentHandlerBase
{

    /**
     * Returns the configuration array
     */
    public function getConfiguration()
    {
        return [
            // common parameters for all adapters
            'common' => array(
                'returnRoute' => 'bankController/return',
            ),
            // adapter-specific parameters
            'adapters' => \yii\helpers\ArrayHelper::merge(

// create the payment service
$service = MyPaymentHandler::createPaymentService();

// create a transaction object
$transaction = $service->createTransaction(1234, 234, ['comment' => 'Comment']);

// render the widget
echo \dlds\payment\widgets\PaymentWidget::widget([
    'forms' => $service->generateForms($transaction),
]);


class MyPaymentWidget extends PaymentWidget
{
    protected function generateSubmit(Form $form) {
        return Html::submitButton('MyCustomLabel');
    }
}

$service = PaymentHandler::createPaymentService();
$response = $service->handleResponse($_REQUEST);

// re-generate the transaction object from the response
$transaction = $response->getTransaction();

if ($response->isSuccessful()) {
	// see the Transaction object for more details
	echo $transaction->getTransactionId();
}