tests for offline payments and paypal standard
This commit is contained in:
		
							
								
								
									
										49
									
								
								modules/OfflinePayments/Jobs/CreatePaymentMethod.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								modules/OfflinePayments/Jobs/CreatePaymentMethod.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Modules\OfflinePayments\Jobs;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Job;
 | 
			
		||||
use App\Utilities\Modules;
 | 
			
		||||
 | 
			
		||||
class CreatePaymentMethod extends Job
 | 
			
		||||
{
 | 
			
		||||
    protected $request;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new job instance.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $request
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct($request)
 | 
			
		||||
    {
 | 
			
		||||
        $this->request = $this->getRequestInstance($request);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Execute the job.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function handle()
 | 
			
		||||
    {
 | 
			
		||||
        $methods = json_decode(setting('offline-payments.methods'), true);
 | 
			
		||||
 | 
			
		||||
        $payment_method = [
 | 
			
		||||
            'code' => 'offline-payments.' . $this->request->get('code') . '.' . (count($methods) + 1),
 | 
			
		||||
            'name' => $this->request->get('name'),
 | 
			
		||||
            'customer' => $this->request->get('customer'),
 | 
			
		||||
            'order' => $this->request->get('order'),
 | 
			
		||||
            'description' => $this->request->get('description'),
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        $methods[] = $payment_method;
 | 
			
		||||
 | 
			
		||||
        setting()->set('offline-payments.methods', json_encode($methods));
 | 
			
		||||
 | 
			
		||||
        setting()->save();
 | 
			
		||||
 | 
			
		||||
        Modules::clearPaymentMethodsCache();
 | 
			
		||||
 | 
			
		||||
        return $payment_method;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										53
									
								
								modules/OfflinePayments/Jobs/DeletePaymentMethod.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								modules/OfflinePayments/Jobs/DeletePaymentMethod.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Modules\OfflinePayments\Jobs;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Job;
 | 
			
		||||
use App\Utilities\Modules;
 | 
			
		||||
 | 
			
		||||
class DeletePaymentMethod extends Job
 | 
			
		||||
{
 | 
			
		||||
    protected $request;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new job instance.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $request
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct($request)
 | 
			
		||||
    {
 | 
			
		||||
        $this->request = $this->getRequestInstance($request);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Execute the job.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function handle()
 | 
			
		||||
    {
 | 
			
		||||
        $methods = json_decode(setting('offline-payments.methods'), true);
 | 
			
		||||
 | 
			
		||||
        $payment_method = [];
 | 
			
		||||
 | 
			
		||||
        $code = $this->request->get('code');
 | 
			
		||||
 | 
			
		||||
        foreach ($methods as $key => $method) {
 | 
			
		||||
            if ($method['code'] != $code) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $payment_method = $methods[$key];
 | 
			
		||||
 | 
			
		||||
            unset($methods[$key]);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        setting()->set('offline-payments.methods', json_encode($methods));
 | 
			
		||||
 | 
			
		||||
        setting()->save();
 | 
			
		||||
 | 
			
		||||
        Modules::clearPaymentMethodsCache();
 | 
			
		||||
 | 
			
		||||
        return $payment_method;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										61
									
								
								modules/OfflinePayments/Jobs/UpdatePaymentMethod.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								modules/OfflinePayments/Jobs/UpdatePaymentMethod.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,61 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Modules\OfflinePayments\Jobs;
 | 
			
		||||
 | 
			
		||||
use App\Abstracts\Job;
 | 
			
		||||
use App\Utilities\Modules;
 | 
			
		||||
 | 
			
		||||
class UpdatePaymentMethod extends Job
 | 
			
		||||
{
 | 
			
		||||
    protected $request;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new job instance.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  $request
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct($request)
 | 
			
		||||
    {
 | 
			
		||||
        $this->request = $this->getRequestInstance($request);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Execute the job.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function handle()
 | 
			
		||||
    {
 | 
			
		||||
        $methods = json_decode(setting('offline-payments.methods'), true);
 | 
			
		||||
 | 
			
		||||
        $payment_method = [];
 | 
			
		||||
 | 
			
		||||
        $code = $this->request->get('update_code');
 | 
			
		||||
 | 
			
		||||
        foreach ($methods as $key => $method) {
 | 
			
		||||
            if ($method['code'] != $code) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $method = explode('.', $code);
 | 
			
		||||
 | 
			
		||||
            $payment_method = [
 | 
			
		||||
                'code' => 'offline-payments.' . $this->request->get('code') . '.' . $method[2],
 | 
			
		||||
                'name' => $this->request->get('name'),
 | 
			
		||||
                'customer' => $this->request->get('customer'),
 | 
			
		||||
                'order' => $this->request->get('order'),
 | 
			
		||||
                'description' => $this->request->get('description'),
 | 
			
		||||
            ];
 | 
			
		||||
 | 
			
		||||
            $methods[$key] = $payment_method;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        setting()->set('offline-payments.methods', json_encode($methods));
 | 
			
		||||
 | 
			
		||||
        setting()->save();
 | 
			
		||||
 | 
			
		||||
        Modules::clearPaymentMethodsCache();
 | 
			
		||||
 | 
			
		||||
        return $payment_method;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user