1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00
invoiceninja/app/Ninja/PaymentDrivers/PayPalExpressPaymentDriver.php

74 lines
2.3 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Ninja\PaymentDrivers;
2016-06-20 16:14:43 +02:00
class PayPalExpressPaymentDriver extends BasePaymentDriver
{
2016-06-22 20:42:09 +02:00
public function gatewayTypes()
2016-06-20 16:14:43 +02:00
{
return [
2017-01-30 20:40:43 +01:00
GATEWAY_TYPE_PAYPAL,
2016-06-20 16:14:43 +02:00
];
}
2016-07-21 14:35:23 +02:00
protected function paymentDetails($paymentMethod = false)
2016-06-20 16:14:43 +02:00
{
$data = parent::paymentDetails();
$data['ButtonSource'] = 'InvoiceNinja_SP';
$data['solutionType'] = 'Sole'; // show 'Pay with credit card' option
2017-03-28 11:47:11 +02:00
$data['transactionId'] = $data['transactionId'] . '-' . time();
2016-06-20 16:14:43 +02:00
return $data;
}
2016-07-21 14:35:23 +02:00
protected function creatingPayment($payment, $paymentMethod)
2016-06-20 16:14:43 +02:00
{
$payment->payer_id = $this->input['PayerID'];
return $payment;
}
protected function paymentUrl($gatewayTypeAlias)
{
$url = parent::paymentUrl($gatewayTypeAlias);
// PayPal doesn't allow being run in an iframe so we need to open in new tab
if ($this->account()->iframe_url) {
return 'javascript:window.open("' . $url . '", "_blank")';
} else {
return $url;
}
}
2017-11-20 15:32:17 +01:00
protected function updateClientFromOffsite($transRef, $paymentRef)
{
$response = $this->gateway()->fetchCheckout([
'token' => $transRef
])->send();
$data = $response->getData();
$client = $this->client();
2017-11-20 16:02:39 +01:00
if (empty($data['SHIPTOSTREET'])) {
return;
}
2019-02-18 15:08:16 +01:00
$client->shipping_address1 = isset($data['SHIPTOSTREET']) ? trim($data['SHIPTOSTREET']) : '';
2019-10-27 10:41:19 +01:00
$client->shipping_address2 = isset($data['SHIPTOSTREET2']) ? trim($data['SHIPTOSTREET2']) : '';
2019-02-18 15:08:16 +01:00
$client->shipping_city = isset($data['SHIPTOCITY']) ? trim($data['SHIPTOCITY']) : '';
$client->shipping_state = isset($data['SHIPTOSTATE']) ? trim($data['SHIPTOSTATE']) : '';
2019-01-30 11:45:46 +01:00
$client->shipping_postal_code = isset($data['SHIPTOZIP']) ? trim($data['SHIPTOZIP']) : '';
2017-11-20 15:32:17 +01:00
2019-02-18 15:08:16 +01:00
if (isset($data['SHIPTOCOUNTRYCODE']) && $country = cache('countries')->filter(function ($item) use ($data) {
2017-11-20 15:32:17 +01:00
return strtolower($item->iso_3166_2) == strtolower(trim($data['SHIPTOCOUNTRYCODE']));
})->first()) {
$client->shipping_country_id = $country->id;
} else {
$client->shipping_country_id = null;
}
$client->save();
}
2016-06-20 16:14:43 +02:00
}