diff --git a/app/PaymentDrivers/PayPalProPaymentDriver.php b/app/PaymentDrivers/PayPalRestPaymentDriver.php similarity index 85% rename from app/PaymentDrivers/PayPalProPaymentDriver.php rename to app/PaymentDrivers/PayPalRestPaymentDriver.php index 7d49219ad3fc..7ed1ab9a609d 100644 --- a/app/PaymentDrivers/PayPalProPaymentDriver.php +++ b/app/PaymentDrivers/PayPalRestPaymentDriver.php @@ -14,7 +14,6 @@ namespace App\PaymentDrivers; use Omnipay\Omnipay; use App\Models\Invoice; -use App\Utils\CurlUtils; use Omnipay\Common\Item; use App\Models\SystemLog; use App\Models\GatewayType; @@ -24,7 +23,7 @@ use App\Utils\Traits\MakesHash; use App\Exceptions\PaymentFailed; use Illuminate\Support\Facades\Http; -class PayPalProPaymentDriver extends BaseDriver +class PayPalRestPaymentDriver extends BaseDriver { use MakesHash; @@ -61,17 +60,9 @@ class PayPalProPaymentDriver extends BaseDriver $this->company_gateway->gateway->provider ); - $this->omnipay_gateway = Omnipay::create('PayPal_Rest'); - - // Initialise the gateway - $this->omnipay_gateway->initialize(array( - 'clientId' => '', - 'secret' => '', - 'testMode' => true, // Or false when you are ready for live transactions - )); + $this->omnipay_gateway->initialize((array) $this->company_gateway->getConfig()); - return $this; - // $this->omnipay_gateway->initialize((array) $this->company_gateway->getConfig()); + return $this; } public function setPaymentMethod($payment_method_id) @@ -105,34 +96,17 @@ class PayPalProPaymentDriver extends BaseDriver $this->payment_hash->data = array_merge((array) $this->payment_hash->data, ['amount' => $data['total']['amount_with_fee']]); $this->payment_hash->save(); - // $data['token'] = base64_decode($this->omnipay_gateway->getToken()); - $access_token = $this->omnipay_gateway->getToken(); - $headers = [ 'Accept' => 'application/json', 'Content-type' => 'application/json', - // 'Authorization' => $basic, 'Accept-Language' => 'en_US', - 'User-Agent' => 'curl/7.68.0' ]; - // $r = Http::withHeaders($headers)->post('https://api-m.sandbox.paypal.com/v1/oauth2/token?grant_type=client_credentials'); - - - // if ($response) { - // return $response; - // } - -// $r = Http::withToken($access_token) - // ->withHeaders(['Accept-Language' => 'en_US'])->post("https://api-m.sandbox.paypal.com/v1/identity/generate-token",[]); - - - $r = Http:: - withToken($access_token) - ->withHeaders($headers) - ->post("https://api-m.sandbox.paypal.com/v1/identity/generate-token",['body' => '']); + $r = Http::withToken($access_token) + ->withHeaders($headers) + ->post("https://api-m.sandbox.paypal.com/v1/identity/generate-token",['body' => '']); nlog($r->body()); dd($r); diff --git a/database/migrations/2023_06_20_123355_add_paypal_rest_payment_driver.php b/database/migrations/2023_06_20_123355_add_paypal_rest_payment_driver.php new file mode 100644 index 000000000000..d3d4b2a1c369 --- /dev/null +++ b/database/migrations/2023_06_20_123355_add_paypal_rest_payment_driver.php @@ -0,0 +1,49 @@ +clientId = ""; + $fields->secret = ""; + $fields->testMode = false; + + + $paypal = new Gateway; + $paypal->id = 60; + $paypal->name = 'PayPal REST'; + $paypal->key = '80af24a6a691230bbec33e930ab40665'; + $paypal->provider = 'PayPal_Rest'; + $paypal->is_offsite = false; + $paypal->fields = \json_encode($fields); + $paypal->visible = 1; + $paypal->site_url = 'https://www.paypal.com/'; + $paypal->save(); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}; diff --git a/database/seeders/PaymentLibrariesSeeder.php b/database/seeders/PaymentLibrariesSeeder.php index b7420fb8c4ee..4a096febef58 100644 --- a/database/seeders/PaymentLibrariesSeeder.php +++ b/database/seeders/PaymentLibrariesSeeder.php @@ -83,6 +83,7 @@ class PaymentLibrariesSeeder extends Seeder ['id' => 57, 'name' => 'Square', 'provider' => 'Square', 'is_offsite' => false, 'sort_order' => 21, 'key' => '65faab2ab6e3223dbe848b1686490baz', 'fields' => '{"accessToken":"","applicationId":"","locationId":"","testMode":false}'], ['id' => 58, 'name' => 'Razorpay', 'provider' => 'Razorpay', 'is_offsite' => false, 'sort_order' => 21, 'key' => 'hxd6gwg3ekb9tb3v9lptgx1mqyg69zu9', 'fields' => '{"apiKey":"","apiSecret":""}'], ['id' => 59, 'name' => 'Forte', 'provider' => 'Forte', 'is_offsite' => false, 'sort_order' => 21, 'key' => 'kivcvjexxvdiyqtj3mju5d6yhpeht2xs', 'fields' => '{"testMode":false,"apiLoginId":"","apiAccessId":"","secureKey":"","authOrganizationId":"","organizationId":"","locationId":""}'], + ['id' => 60, 'name' => 'PayPal REST', 'provider' => 'PayPal_Rest', 'key' => '80af24a6a691230bbec33e930ab40665', 'fields' => '{"clientId":"","secret":"","signature":"","testMode":false}'], ]; foreach ($gateways as $gateway) { @@ -99,7 +100,7 @@ class PaymentLibrariesSeeder extends Seeder Gateway::query()->update(['visible' => 0]); - Gateway::whereIn('id', [1,3,7,11,15,20,39,46,55,50,57,52,58,59])->update(['visible' => 1]); + Gateway::whereIn('id', [1,3,7,11,15,20,39,46,55,50,57,52,58,59,60])->update(['visible' => 1]); if (Ninja::isHosted()) { Gateway::whereIn('id', [20])->update(['visible' => 0]);