5
5
use PayPalCheckoutSdk \Core \PayPalHttpClient ;
6
6
use PayPalCheckoutSdk \Orders \OrdersGetRequest ;
7
7
use PayPalCheckoutSdk \Payments \AuthorizationsCaptureRequest ;
8
+ use PayPalCheckoutSdk \Payments \CapturesGetRequest ;
8
9
use R64 \Checkout \Contracts \Customer ;
9
10
use R64 \Checkout \Contracts \Customer as CustomerContract ;
10
11
use R64 \Checkout \Contracts \PaymentHandler ;
@@ -43,6 +44,8 @@ public function purchase(array $order, array $paymentDetails, Customer $customer
43
44
throw new PaymentException ("Paypal Capture failed " );
44
45
}
45
46
47
+ $ captureResponse = $ this ->captureDetails ($ this ->getPaypalCaptureId ($ captureResponse ));
48
+
46
49
return $ this ->recordPurchase ($ paymentDetails , $ order , $ orderResponse , $ captureResponse , $ customer );
47
50
}
48
51
@@ -100,6 +103,15 @@ protected function getPaypalCaptureId(\PayPalHttp\HttpResponse $response): strin
100
103
return $ response ->result ->id ;
101
104
}
102
105
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
+
103
115
/**
104
116
* @param array $paymentDetails
105
117
*
@@ -112,6 +124,12 @@ protected function capture(array $paymentDetails)
112
124
return $ this ->client ->execute ($ request );
113
125
}
114
126
127
+ protected function captureDetails ($ captureId )
128
+ {
129
+ $ request = new CapturesGetRequest ($ captureId );
130
+ return $ this ->client ->execute ($ request );
131
+ }
132
+
115
133
protected function recordPurchase (array $ paymentDetails , array $ order , $ orderResponse , $ captureResponse , CustomerContract $ customer )
116
134
{
117
135
$ customerId = \R64 \Checkout \Facades \Customer::getForeignKey ();
@@ -126,6 +144,7 @@ protected function recordPurchase(array $paymentDetails, array $order, $orderRes
126
144
'paypal_authorization_id ' => $ paymentDetails ['authorization_id ' ],
127
145
'paypal_capture_id ' => $ this ->getPaypalCaptureId ($ captureResponse ),
128
146
'paypal_payer_id ' => $ this ->getPaypalPayerId ($ orderResponse ),
147
+ 'paypal_fee ' => $ this ->getFee ($ captureResponse )
129
148
], $ customer );
130
149
}
131
150
}
0 commit comments