mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Minor fixes
This commit is contained in:
parent
f0dbb10f93
commit
74462c4ef2
@ -41,6 +41,8 @@ class PayPalPPCPPaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
private string $paypal_payment_method = '';
|
private string $paypal_payment_method = '';
|
||||||
|
|
||||||
|
private ?int $gateway_type_id = null;
|
||||||
|
|
||||||
protected mixed $access_token = null;
|
protected mixed $access_token = null;
|
||||||
|
|
||||||
protected ?Carbon $token_expiry = null;
|
protected ?Carbon $token_expiry = null;
|
||||||
@ -70,13 +72,6 @@ class PayPalPPCPPaymentDriver extends BaseDriver
|
|||||||
public function gatewayTypes(): array
|
public function gatewayTypes(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
// $funding_options = [];
|
|
||||||
|
|
||||||
// foreach ($this->company_gateway->fees_and_limits as $key => $value) {
|
|
||||||
// if ($value->is_enabled) {
|
|
||||||
// $funding_options[] = (int)$key;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
return collect($this->company_gateway->fees_and_limits)
|
return collect($this->company_gateway->fees_and_limits)
|
||||||
->filter(function ($fee){
|
->filter(function ($fee){
|
||||||
return $fee->is_enabled;
|
return $fee->is_enabled;
|
||||||
@ -84,7 +79,53 @@ class PayPalPPCPPaymentDriver extends BaseDriver
|
|||||||
return (int)$key;
|
return (int)$key;
|
||||||
})->toArray();
|
})->toArray();
|
||||||
|
|
||||||
// return $funding_options;
|
}
|
||||||
|
|
||||||
|
private function getPaymentMethod($gateway_type_id): int
|
||||||
|
{
|
||||||
|
$method = PaymentType::PAYPAL;
|
||||||
|
|
||||||
|
match($gateway_type_id){
|
||||||
|
"3" => $method = PaymentType::PAYPAL,
|
||||||
|
"1" => $method = PaymentType::CREDIT_CARD_OTHER,
|
||||||
|
"25" => $method = PaymentType::VENMO,
|
||||||
|
};
|
||||||
|
|
||||||
|
return $method;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getFundingOptions():string
|
||||||
|
{
|
||||||
|
|
||||||
|
$enums = [
|
||||||
|
3 => 'paypal',
|
||||||
|
1 => 'card',
|
||||||
|
25 => 'venmo',
|
||||||
|
// 9 => 'sepa',
|
||||||
|
// 12 => 'bancontact',
|
||||||
|
// 17 => 'eps',
|
||||||
|
// 15 => 'giropay',
|
||||||
|
// 13 => 'ideal',
|
||||||
|
// 26 => 'mercadopago',
|
||||||
|
// 27 => 'mybank',
|
||||||
|
// 28 => 'paylater',
|
||||||
|
// 16 => 'p24',
|
||||||
|
// 7 => 'sofort'
|
||||||
|
];
|
||||||
|
|
||||||
|
$funding_options = '';
|
||||||
|
|
||||||
|
foreach($this->company_gateway->fees_and_limits as $key => $value) {
|
||||||
|
|
||||||
|
if($value->is_enabled) {
|
||||||
|
|
||||||
|
$funding_options .=$enums[$key].',';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return rtrim($funding_options, ',');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,6 +170,8 @@ class PayPalPPCPPaymentDriver extends BaseDriver
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->gateway_type_id = $payment_method_id;
|
||||||
|
|
||||||
$this->paypal_payment_method = $this->funding_options[$payment_method_id];
|
$this->paypal_payment_method = $this->funding_options[$payment_method_id];
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -160,6 +203,7 @@ class PayPalPPCPPaymentDriver extends BaseDriver
|
|||||||
$data['token'] = $this->getClientToken();
|
$data['token'] = $this->getClientToken();
|
||||||
$data['order_id'] = $this->createOrder($data);
|
$data['order_id'] = $this->createOrder($data);
|
||||||
$data['funding_source'] = $this->paypal_payment_method;
|
$data['funding_source'] = $this->paypal_payment_method;
|
||||||
|
$data['gateway_type_id'] = $this->gateway_type_id;
|
||||||
|
|
||||||
return render('gateways.paypal.ppcp.pay', $data);
|
return render('gateways.paypal.ppcp.pay', $data);
|
||||||
|
|
||||||
@ -177,53 +221,19 @@ class PayPalPPCPPaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getFundingOptions():string
|
|
||||||
{
|
|
||||||
|
|
||||||
$enums = [
|
|
||||||
3 => 'paypal',
|
|
||||||
1 => 'card',
|
|
||||||
25 => 'venmo',
|
|
||||||
// 9 => 'sepa',
|
|
||||||
// 12 => 'bancontact',
|
|
||||||
// 17 => 'eps',
|
|
||||||
// 15 => 'giropay',
|
|
||||||
// 13 => 'ideal',
|
|
||||||
// 26 => 'mercadopago',
|
|
||||||
// 27 => 'mybank',
|
|
||||||
// 28 => 'paylater',
|
|
||||||
// 16 => 'p24',
|
|
||||||
// 7 => 'sofort'
|
|
||||||
];
|
|
||||||
|
|
||||||
$funding_options = '';
|
|
||||||
|
|
||||||
foreach($this->company_gateway->fees_and_limits as $key => $value) {
|
|
||||||
|
|
||||||
if($value->is_enabled) {
|
|
||||||
|
|
||||||
$funding_options .=$enums[$key].',';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtrim($funding_options, ',');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function processPaymentResponse($request)
|
public function processPaymentResponse($request)
|
||||||
{
|
{
|
||||||
nlog($request['gateway_response']);
|
nlog($request->all());
|
||||||
|
|
||||||
|
$request['gateway_response'] = str_replace("Error: ", "", $request['gateway_response']);
|
||||||
$response = json_decode($request['gateway_response'], true);
|
$response = json_decode($request['gateway_response'], true);
|
||||||
|
|
||||||
nlog($response);
|
nlog($response);
|
||||||
|
|
||||||
if($response['status'] == 'COMPLETED' && isset($response['purchase_units'])) {
|
if(isset($response['status']) && $response['status'] == 'COMPLETED' && isset($response['purchase_units'])) {
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'payment_type' => PaymentType::PAYPAL,
|
'payment_type' => $this->getPaymentMethod($request->gateway_type_id),
|
||||||
'amount' => $response['purchase_units'][0]['amount']['value'],
|
'amount' => $response['purchase_units'][0]['amount']['value'],
|
||||||
'transaction_reference' => $response['purchase_units'][0]['payments']['captures'][0]['id'],
|
'transaction_reference' => $response['purchase_units'][0]['payments']['captures'][0]['id'],
|
||||||
'gateway_type_id' => GatewayType::PAYPAL,
|
'gateway_type_id' => GatewayType::PAYPAL,
|
||||||
@ -244,6 +254,9 @@ class PayPalPPCPPaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
if(isset($response['headers']) ?? false)
|
||||||
|
unset($response['headers']);
|
||||||
|
|
||||||
SystemLogger::dispatch(
|
SystemLogger::dispatch(
|
||||||
['response' => $response],
|
['response' => $response],
|
||||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||||
@ -253,8 +266,9 @@ class PayPalPPCPPaymentDriver extends BaseDriver
|
|||||||
$this->client->company,
|
$this->client->company,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$message = $response['body']['details'][0]['description'] ?? 'Payment failed. Please try again.';
|
||||||
|
|
||||||
throw new PaymentFailed('Payment failed. Please try again.', 401);
|
throw new PaymentFailed($message, 400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
@csrf
|
@csrf
|
||||||
<input type="hidden" name="payment_hash" value="{{ $payment_hash }}">
|
<input type="hidden" name="payment_hash" value="{{ $payment_hash }}">
|
||||||
<input type="hidden" name="company_gateway_id" value="{{ $gateway->company_gateway->id }}">
|
<input type="hidden" name="company_gateway_id" value="{{ $gateway->company_gateway->id }}">
|
||||||
|
<input type="hidden" name="gateway_type_id" id="gateway_type_id" value="{{ $gateway_type_id }}">
|
||||||
<input type="hidden" name="gateway_response" id="gateway_response">
|
<input type="hidden" name="gateway_response" id="gateway_response">
|
||||||
<input type="hidden" name="amount_with_fee" id="amount_with_fee" value="{{ $total['amount_with_fee'] }}"/>
|
<input type="hidden" name="amount_with_fee" id="amount_with_fee" value="{{ $total['amount_with_fee'] }}"/>
|
||||||
</form>
|
</form>
|
||||||
@ -53,16 +54,13 @@
|
|||||||
document.getElementById("gateway_response").value =JSON.stringify( details );
|
document.getElementById("gateway_response").value =JSON.stringify( details );
|
||||||
document.getElementById("server_response").submit();
|
document.getElementById("server_response").submit();
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
onCancel: function() {
|
onCancel: function() {
|
||||||
window.location.href = "/client/invoices/";
|
window.location.href = "/client/invoices/";
|
||||||
},
|
},
|
||||||
onError: function(err) {
|
onError: function(error) {
|
||||||
console.log("there was an error")
|
document.getElementById("gateway_response").value = error;
|
||||||
console.log(err)
|
document.getElementById("server_response").submit();
|
||||||
// document.getElementById("gateway_response").value =JSON.stringify( err );
|
|
||||||
// document.getElementById("server_response").submit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}).render('#paypal-button-container');
|
}).render('#paypal-button-container');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user