Skip to content

Commit

Permalink
Merge pull request #6 from OdranHUSSON/feature/paypal
Browse files Browse the repository at this point in the history
Payment method remove hardcode
  • Loading branch information
OdranHUSSON committed Mar 1, 2020
2 parents fbb8e96 + ed56b61 commit a98bf46
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion app/Http/Controllers/PaypalController.php
Expand Up @@ -6,6 +6,7 @@
use Crater\CompanySetting;
use Crater\Invoice;
use Crater\Payment;
use Crater\PaymentMethod;
use Illuminate\Http\Request;
use Srmklive\PayPal\Services\ExpressCheckout;
use Validator;
Expand Down Expand Up @@ -33,6 +34,24 @@ protected function getInvoice($invoiceId) {
return $invoice;
}

/**
* @param $name
*
* @return PaymentMethod
*/
protected function getOrCreatePaymentMethod($name) {
$paymentMethod = PaymentMethod::where('name', $name)->where('company_id', $this::COMPANY_ID)->first();

if($paymentMethod === NULL) {
$paymentMethod = new PaymentMethod();
$paymentMethod->name($name);
$paymentMethod->company_id($this::COMPANY_ID);
$paymentMethod->save();
}

return $paymentMethod;
}

/**
* @param $invoiceId
*
Expand Down Expand Up @@ -143,6 +162,9 @@ public function paymentSuccess($invoiceId) {
protected function storePayment($invoiceId) {

if ($this->getPaymentByInvoiceId($invoiceId) === NULL) {

$paymentMethod = $this->getOrCreatePaymentMethod('Paypal');

$invoice = $this->getInvoice($invoiceId);
$payment_prefix = CompanySetting::getSetting('payment_prefix', $this::COMPANY_ID);
$payment_number = Payment::getNextPaymentNumber($payment_prefix);
Expand All @@ -158,7 +180,7 @@ protected function storePayment($invoiceId) {
'user_id' => $invoice->user->id,
'company_id' => $this::COMPANY_ID,
'invoice_id' => $invoice->id,
'payment_method_id' => 9,
'payment_method_id' => $paymentMethod->id,
'amount' => $invoice->total,
'notes' => $invoice->unique_hash,
'unique_hash' => str_random(60)
Expand Down

0 comments on commit a98bf46

Please sign in to comment.