public function getEC() { $logger = new PPLoggingManager('GetExpressCheckout'); // ## GetExpressCheckoutDetailsReq $getExpressCheckoutDetailsReq = new GetExpressCheckoutDetailsReq(); // A timestamped token, the value of which was returned by // `SetExpressCheckout` response. $setEc = new SetExpressCheckout(); $setEcResponse = $setEc->setExpressCheckout(); var_dump($setEcResponse->Token); $getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($setEcResponse->Token); $getExpressCheckoutDetailsReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest; // ## Creating service wrapper object // Creating service wrapper object to make API call and loading // configuration file for your credentials and endpoint $service = new PayPalAPIInterfaceServiceService(); try { // ## Making API call // Invoke the appropriate method corresponding to API in service // wrapper object $response = $service->GetExpressCheckoutDetails($getExpressCheckoutDetailsReq); } catch (Exception $ex) { $logger->error("Error Message : " + $ex->getMessage()); } // ## Accessing response parameters // You can access the response parameters using variables in // response object as shown below // ### Success values if ($response->Ack == "Success") { // PayerID is PayPal Customer Account identification number // ($response->GetExpressCheckoutDetailsResponseDetails->PayerInfo->PayerID). This // value will be null unless you authorize the payment by // redirecting to PayPal after `SetExpressCheckout` call. $logger->log("PayerID : " . $response->GetExpressCheckoutDetailsResponseDetails->PayerInfo->PayerID); } else { $logger->error("API Error Message : " . $response->Errors[0]->LongMessage); } return $response; }
<?php $path = '../../lib'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'services/PayPalAPIInterfaceService/PayPalAPIInterfaceServiceService.php'; require_once 'PPLoggingManager.php'; session_start(); $logger = new PPLoggingManager('GetExpressCheckout'); $token = $_REQUEST['token']; $getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token); $getExpressCheckoutDetailsRequest->Version = 92.0; $getExpressCheckoutReq = new GetExpressCheckoutDetailsReq(); $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest; $paypalService = new PayPalAPIInterfaceServiceService(); $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq); echo '<pre>'; print_r($getECResponse); echo '</pre>'; if ($getECResponse->Ack == 'Success') { ?> <html> <body> </body> </html> <?php require_once '../Response.php'; }
public function getExpressCheckout($setToken) { $logger = new PPLoggingManager('GetTransactionDetails'); $token = $setToken; $getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token); $getExpressCheckoutReq = new GetExpressCheckoutDetailsReq(); $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest; /* Creating service wrapper object Creating service wrapper object to make API call and loading Configuration::getAcctAndConfig() returns array that contains credential and config parameters */ $paypalService = new PayPalAPIInterfaceServiceService(); try { /* wrap API method calls on the service object with a try catch */ $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq); } catch (Exception $ex) { $logger->error("API Error Message : " . $ex->getMessage()); } if ($getECResponse->Ack == 'Success') { return $getECResponse; } else { $logger->error("API Error Message : " . $getECResponse); return FALSE; } }
public function confirm($id, $token, $payer_id) { $products = $this->products; $product = $products[$id]; if (empty($product)) { return; } $paypal_service = new PayPalAPIInterfaceServiceService($this->pp_settings); $ec_details_req_type = new GetExpressCheckoutDetailsRequestType($token); $ec_detail_req = new GetExpressCheckoutDetailsReq(); $ec_detail_req->GetExpressCheckoutDetailsRequest = $ec_details_req_type; $ec_resp = $paypal_service->GetExpressCheckoutDetails($ec_detail_req); if (!$ec_resp && $ec_resp->Ack != 'Success') { throw new Exception("Paypal Request Failed"); } //we now have the payer info $payer_info = $ec_resp->GetExpressCheckoutDetailsResponseDetails->PayerInfo; if ($product['recurring']) { $order_total = new BasicAmountType($product['currency'], $product['init_amount']); } else { $order_total = new BasicAmountType($product['currency'], $product['amount']); } $payment_details = new PaymentDetailsType(); $payment_details->OrderTotal = $order_total; $payment_details->NotifyURL = $this->thankyou_url . '?action=ipn&id=' . $id; $do_ec_details = new DoExpressCheckoutPaymentRequestDetailsType(); $do_ec_details->PayerID = $payer_id; $do_ec_details->Token = $token; $do_ec_details->PaymentDetails[0] = $payment_details; $do_ec_request = new DoExpressCheckoutPaymentRequestType(); $do_ec_request->DoExpressCheckoutPaymentRequestDetails = $do_ec_details; if ($order_total->value > 0) { $do_ec = new DoExpressCheckoutPaymentReq(); $do_ec->DoExpressCheckoutPaymentRequest = $do_ec_request; $do_ec_resp = $paypal_service->DoExpressCheckoutPayment($do_ec); if (!$do_ec_resp || $do_ec_resp->Ack != 'Success') { throw new Exception("Paypal Checkout Error Has Occured"); } //we now have a payment info. Yeehaaa $payment_info = current($do_ec_resp->DoExpressCheckoutPaymentResponseDetails->PaymentInfo); $accept_statuses = array('Completed', 'In-Progress', 'Pending', 'Processed'); if (!in_array($payment_info->PaymentStatus, $accept_statuses)) { throw new Exception("Paypal Payment Checkout Failed"); } } if ($product['recurring']) { //create a recurring payment profile $schedule_details = new ScheduleDetailsType(); $payment_billing_period = new BillingPeriodDetailsType(); $payment_billing_period->BillingFrequency = $product['recur_billing_frequency']; $payment_billing_period->BillingPeriod = $product['recur_billing_period']; $payment_billing_period->Amount = new BasicAmountType($product['currency'], $product['recur_amount']); $schedule_details->PaymentPeriod = $payment_billing_period; $schedule_details->Description = sprintf("%s %s", $product['name'], __("Subscription", "wishlist-member")); $recur_profile_details = new RecurringPaymentsProfileDetailsType(); $recur_profile_details->BillingStartDate = date(DATE_ATOM, strtotime(sprintf("+%s %s", $product['recur_billing_frequency'], $product['recur_billing_period']))); $create_recur_paypay_profile_details = new CreateRecurringPaymentsProfileRequestDetailsType(); $create_recur_paypay_profile_details->Token = $token; $create_recur_paypay_profile_details->ScheduleDetails = $schedule_details; $create_recur_paypay_profile_details->RecurringPaymentsProfileDetails = $recur_profile_details; $create_recur_profile = new CreateRecurringPaymentsProfileRequestType(); $create_recur_profile->CreateRecurringPaymentsProfileRequestDetails = $create_recur_paypay_profile_details; $create_recur_profile_req = new CreateRecurringPaymentsProfileReq(); $create_recur_profile_req->CreateRecurringPaymentsProfileRequest = $create_recur_profile; $create_profile_resp = $paypal_service->CreateRecurringPaymentsProfile($create_recur_profile_req); if (!$create_profile_resp || $create_profile_resp->Ack != 'Success') { throw new Exception("Could not create recurring profile"); } } $address = array(); $address['company'] = $payer_info->PayerBusiness; $address['address1'] = $payer_info->Address->Street1; $address['address2'] = $payer_info->Address->Street2; $address['city'] = $payer_info->Address->CityName; $address['state'] = $payer_info->Address->StateOrProvince; $address['zip'] = $payer_info->Address->PostalCode; $address['country'] = $payer_info->Address->CountryName; $_POST['wpm_useraddress'] = $address; $_POST['lastname'] = $payer_info->PayerName->LastName; $_POST['firstname'] = $payer_info->PayerName->FirstName; $_POST['action'] = 'wpm_register'; $_POST['wpm_id'] = $product['sku']; $_POST['username'] = $payer_info->Payer; $_POST['email'] = $payer_info->Payer; $_POST['password1'] = $_POST['password2'] = $this->wlm->PassGen(); $_POST['sctxnid'] = $product['recurring'] ? $create_profile_resp->CreateRecurringPaymentsProfileResponseDetails->ProfileID : $payment_info->TransactionID; $pending_statuses = array('In-Progress', 'Pending'); if (in_array($payment_info->PaymentStatus, $pending_statuses) || $create_profile_resp->CreateRecurringPaymentsProfileResponseDetails->ProfileStatus == 'PendingProfile') { $this->wlm->ShoppingCartRegistration(null, null, 'Paypal Pending'); } else { $this->wlm->ShoppingCartRegistration(); } }