Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass data to PayPal to pre-fill billing info #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion code/PayPalGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -216,4 +233,4 @@ public function confirm($data) {

return $result;
}
}
}