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';
|
2016-09-26 08:20:06 +02:00
|
|
|
$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;
|
|
|
|
}
|
2017-03-29 20:45:41 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-11-20 15:32:17 +01:00
|
|
|
$client->shipping_address1 = trim($data['SHIPTOSTREET']);
|
|
|
|
$client->shipping_address2 = '';
|
|
|
|
$client->shipping_city = trim($data['SHIPTOCITY']);
|
2017-12-14 15:24:06 +01:00
|
|
|
$client->shipping_state = isset($data['SHIPTOSTATE']) ? trim($data['SHIPTOSTATE']) : '';
|
2017-11-20 15:32:17 +01:00
|
|
|
$client->shipping_postal_code = trim($data['SHIPTOZIP']);
|
|
|
|
|
|
|
|
if ($country = cache('countries')->filter(function ($item) use ($data) {
|
|
|
|
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
|
|
|
}
|