Skip to content

Commit 2b1fc04

Browse files
Update paypal fee handling
1 parent bf74c07 commit 2b1fc04

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

config/checkout.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@
4848
'fixed_fee' => env('CHECKOUT_STRIPE_FIXED_FEE', 30)
4949
],
5050

51-
'paypal' => [
52-
'percentage_fee' => env('CHECKOUT_PAYPAL_PERCENTAGE_FEE', 2.9 / 100),
53-
'fixed_fee' => env('CHECKOUT_PAYPAL_FIXED_FEE', 30)
54-
],
55-
5651
/*
5752
* Shipping city and state is automatically resolved from zip code
5853
* using GeoNames service http://www.geonames.org/

src/Models/OrderPurchase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static function makeOne(array $data, CustomerContract $customer)
5454
$purchase->paypal_authorization_id = $data['paypal_authorization_id'];
5555
$purchase->paypal_capture_id = $data['paypal_capture_id'];
5656
$purchase->paypal_payer_id = $data['paypal_payer_id'];
57-
$purchase->paypal_fee = ceil($purchase->amount * config('checkout.paypal.percentage_fee')) + config('checkout.paypal.fixed_fee');
57+
$purchase->paypal_fee = $data['paypal_fee'];
5858
}
5959

6060
$purchase->save();

src/PaypalPaymentHandler.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PayPalCheckoutSdk\Core\PayPalHttpClient;
66
use PayPalCheckoutSdk\Orders\OrdersGetRequest;
77
use PayPalCheckoutSdk\Payments\AuthorizationsCaptureRequest;
8+
use PayPalCheckoutSdk\Payments\CapturesGetRequest;
89
use R64\Checkout\Contracts\Customer;
910
use R64\Checkout\Contracts\Customer as CustomerContract;
1011
use R64\Checkout\Contracts\PaymentHandler;
@@ -43,6 +44,8 @@ public function purchase(array $order, array $paymentDetails, Customer $customer
4344
throw new PaymentException("Paypal Capture failed");
4445
}
4546

47+
$captureResponse = $this->captureDetails($this->getPaypalCaptureId($captureResponse));
48+
4649
return $this->recordPurchase($paymentDetails, $order, $orderResponse, $captureResponse, $customer);
4750
}
4851

@@ -100,6 +103,15 @@ protected function getPaypalCaptureId(\PayPalHttp\HttpResponse $response): strin
100103
return $response->result->id;
101104
}
102105

106+
/**
107+
* @param \PayPalHttp\HttpResponse $response
108+
* @return string
109+
*/
110+
protected function getFee(\PayPalHttp\HttpResponse $response): string
111+
{
112+
return (int) (((float) $response->result->seller_receivable_breakdown->paypal_fee->value) * 100);
113+
}
114+
103115
/**
104116
* @param array $paymentDetails
105117
*
@@ -112,6 +124,12 @@ protected function capture(array $paymentDetails)
112124
return $this->client->execute($request);
113125
}
114126

127+
protected function captureDetails($captureId)
128+
{
129+
$request = new CapturesGetRequest($captureId);
130+
return $this->client->execute($request);
131+
}
132+
115133
protected function recordPurchase(array $paymentDetails, array $order, $orderResponse, $captureResponse, CustomerContract $customer)
116134
{
117135
$customerId = \R64\Checkout\Facades\Customer::getForeignKey();
@@ -126,6 +144,7 @@ protected function recordPurchase(array $paymentDetails, array $order, $orderRes
126144
'paypal_authorization_id' => $paymentDetails['authorization_id'],
127145
'paypal_capture_id' => $this->getPaypalCaptureId($captureResponse),
128146
'paypal_payer_id' => $this->getPaypalPayerId($orderResponse),
147+
'paypal_fee' => $this->getFee($captureResponse)
129148
], $customer);
130149
}
131150
}

0 commit comments

Comments
 (0)