mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
refactor for paypal rest
This commit is contained in:
parent
3bdc94ae64
commit
409aa60928
@ -14,7 +14,6 @@ namespace App\PaymentDrivers;
|
|||||||
|
|
||||||
use Omnipay\Omnipay;
|
use Omnipay\Omnipay;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Utils\CurlUtils;
|
|
||||||
use Omnipay\Common\Item;
|
use Omnipay\Common\Item;
|
||||||
use App\Models\SystemLog;
|
use App\Models\SystemLog;
|
||||||
use App\Models\GatewayType;
|
use App\Models\GatewayType;
|
||||||
@ -24,7 +23,7 @@ use App\Utils\Traits\MakesHash;
|
|||||||
use App\Exceptions\PaymentFailed;
|
use App\Exceptions\PaymentFailed;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
class PayPalProPaymentDriver extends BaseDriver
|
class PayPalRestPaymentDriver extends BaseDriver
|
||||||
{
|
{
|
||||||
use MakesHash;
|
use MakesHash;
|
||||||
|
|
||||||
@ -61,17 +60,9 @@ class PayPalProPaymentDriver extends BaseDriver
|
|||||||
$this->company_gateway->gateway->provider
|
$this->company_gateway->gateway->provider
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->omnipay_gateway = Omnipay::create('PayPal_Rest');
|
$this->omnipay_gateway->initialize((array) $this->company_gateway->getConfig());
|
||||||
|
|
||||||
// Initialise the gateway
|
|
||||||
$this->omnipay_gateway->initialize(array(
|
|
||||||
'clientId' => '',
|
|
||||||
'secret' => '',
|
|
||||||
'testMode' => true, // Or false when you are ready for live transactions
|
|
||||||
));
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
// $this->omnipay_gateway->initialize((array) $this->company_gateway->getConfig());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPaymentMethod($payment_method_id)
|
public function setPaymentMethod($payment_method_id)
|
||||||
@ -105,32 +96,15 @@ class PayPalProPaymentDriver extends BaseDriver
|
|||||||
$this->payment_hash->data = array_merge((array) $this->payment_hash->data, ['amount' => $data['total']['amount_with_fee']]);
|
$this->payment_hash->data = array_merge((array) $this->payment_hash->data, ['amount' => $data['total']['amount_with_fee']]);
|
||||||
$this->payment_hash->save();
|
$this->payment_hash->save();
|
||||||
|
|
||||||
// $data['token'] = base64_decode($this->omnipay_gateway->getToken());
|
|
||||||
|
|
||||||
$access_token = $this->omnipay_gateway->getToken();
|
$access_token = $this->omnipay_gateway->getToken();
|
||||||
|
|
||||||
|
|
||||||
$headers = [
|
$headers = [
|
||||||
'Accept' => 'application/json',
|
'Accept' => 'application/json',
|
||||||
'Content-type' => 'application/json',
|
'Content-type' => 'application/json',
|
||||||
// 'Authorization' => $basic,
|
|
||||||
'Accept-Language' => 'en_US',
|
'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');
|
$r = Http::withToken($access_token)
|
||||||
|
|
||||||
|
|
||||||
// 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)
|
->withHeaders($headers)
|
||||||
->post("https://api-m.sandbox.paypal.com/v1/identity/generate-token",['body' => '']);
|
->post("https://api-m.sandbox.paypal.com/v1/identity/generate-token",['body' => '']);
|
||||||
|
|
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Gateway;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!Gateway::find(60))
|
||||||
|
{
|
||||||
|
|
||||||
|
$fields = new \stdClass;
|
||||||
|
$fields->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()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
};
|
@ -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' => 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' => 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' => 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) {
|
foreach ($gateways as $gateway) {
|
||||||
@ -99,7 +100,7 @@ class PaymentLibrariesSeeder extends Seeder
|
|||||||
|
|
||||||
Gateway::query()->update(['visible' => 0]);
|
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()) {
|
if (Ninja::isHosted()) {
|
||||||
Gateway::whereIn('id', [20])->update(['visible' => 0]);
|
Gateway::whereIn('id', [20])->update(['visible' => 0]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user