From 5c73da5ee577f21d1f42d7cac33d73dfd0452a9f Mon Sep 17 00:00:00 2001 From: RuthAdele Date: Tue, 8 Jul 2014 16:49:14 +0930 Subject: [PATCH] Pass data to PayPal to pre-fill billing info --- code/PayPalGateway.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/code/PayPalGateway.php b/code/PayPalGateway.php index 05571ab..c1402db 100644 --- a/code/PayPalGateway.php +++ b/code/PayPalGateway.php @@ -99,6 +99,23 @@ public function authorise($data) { 'LANDINGPAGE' => 'Billing', //can be 'Billing' or 'Login' 'SOLUTIONTYPE' => 'Sole', //require paypal account, or not. Can be or 'Mark' (required) or 'Sole' (not required) ); + + //Check if swipestripe-addresses sub module is present + if (class_exists('Address') && $currentOrder = DataObject::get_one("Order", "ID = '".$data['Reference']."'")) { + + $prefill = array( + //Prefill Shipping data + 'SHIPTONAME' => $currentOrder->BillingFirstName.' '.$currentOrder->BillingSurname, + 'SHIPTOSTREET' => $currentOrder->BillingAddress, + 'SHIPTOSTREET2' => $currentOrder->BillingAddressLine2, + 'SHIPTOCITY' => $currentOrder->BillingCity, + 'SHIPTOSTATE' => $currentOrder->BillingState, + 'SHIPTOCOUNTRYCODE' => $currentOrder->BillingCountryCode, + 'SHIPTOZIP' => $currentOrder->BillingPostalCode + ); + + $payload = array_merge($payload, $prefill); + } $response = $this->callAPI($payload); $body = $this->formatResponse($response->getBody()); @@ -216,4 +233,4 @@ public function confirm($data) { return $result; } -} \ No newline at end of file +}