GetExpressCheckoutDetails() public method

Service Call: GetExpressCheckoutDetails
public GetExpressCheckoutDetails ( GetExpressCheckoutDetailsReq $getExpressCheckoutDetailsReq, mixed $apiCredential = null ) : GetExpressCheckoutDetailsResponseType
$getExpressCheckoutDetailsReq PayPal\PayPalAPI\GetExpressCheckoutDetailsReq
$apiCredential mixed - Optional API credential - can either be a username configured in sdk_config.ini or a ICredential object created dynamically
return PayPal\PayPalAPI\GetExpressCheckoutDetailsResponseType
コード例 #1
0
ファイル: PaypalService.php プロジェクト: Junyue/zidisha2
 public function getExpressCheckoutDetails($token)
 {
     $paypalTransaction = PaypalTransactionQuery::create()->findOneByToken($token);
     if (!$paypalTransaction) {
         \App::abort('Fatal Error');
     }
     $payment = $paypalTransaction->getPayment();
     $getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token);
     $getExpressCheckoutRequest = new GetExpressCheckoutDetailsReq();
     $getExpressCheckoutRequest->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
     try {
         $getExpressCheckoutResponse = $this->payPalApi->GetExpressCheckoutDetails($getExpressCheckoutRequest);
     } catch (PPConnectionException $e) {
         $paymentError = new PaymentError('Error Connecting to PayPal.', $e);
         return $this->paymentBus->getFailedHandler($payment, $paymentError)->redirect();
     }
     if ($getExpressCheckoutResponse->Ack != 'Success') {
         $paymentError = new PaymentError('Error Connecting to PayPal.');
         return $this->paymentBus->getFailedHandler($payment, $paymentError)->redirect();
     }
     try {
         $payPalFinalResponse = $this->doExpressCheckout($getExpressCheckoutResponse->GetExpressCheckoutDetailsResponseDetails->PayerInfo->PayerID, $getExpressCheckoutResponse->GetExpressCheckoutDetailsResponseDetails->Token, $getExpressCheckoutResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails[0]->OrderTotal);
     } catch (PPConnectionException $e) {
         $paymentError = new PaymentError('Error Connecting to PayPal.', $e);
         return $this->paymentBus->getFailedHandler($payment, $paymentError)->redirect();
     }
     if ($payPalFinalResponse->Ack != "Success") {
         $this->logPayPalErrors($payment, $payPalFinalResponse);
         $paymentError = new PaymentError('PayPal transaction failed.');
         return $this->paymentBus->getFailedHandler($payment, $paymentError)->redirect();
     }
     $paymentStatus = $payPalFinalResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->PaymentStatus;
     if ($paymentStatus != "Completed") {
         $paymentError = new PaymentError('PayPal transaction pending');
         return $this->paymentBus->getPendingHandler($payment, $paymentError)->redirect();
     }
     $paypalTransaction->setStatus($paymentStatus);
     $paypalTransaction->save();
     return $this->paymentBus->getCompletedHandler($payment)->redirect();
 }
コード例 #2
0
 * Digital goods are items such as e-books, music files, and digital images distributed in electronic format. The buyer can conveniently purchase digital goods during checkout with a minimum of clicks without leaving your website or interrupting their online activities
 *
*/
$token = urlencode($_REQUEST['token']);
/*
 *  Unique PayPal buyer account identification number as returned in the GetExpressCheckoutDetails response
*/
$payerId = urlencode($_REQUEST['PayerID']);
//--------------------------------------------------------------
// this section is optional if values are retrieved from your database
$token = $_REQUEST['token'];
$getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token);
$getExpressCheckoutReq = new GetExpressCheckoutDetailsReq();
$getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
$paypalService = new PayPalAPIInterfaceServiceService();
$getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
//--------------------------------------------------------------------
/*
 * The total cost of the transaction to the buyer. If shipping cost (not applicable to digital goods) and tax charges are known, include them in this value. If not, this value should be the current sub-total of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. Set this field to 0 if the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment that is not immediately charged. When the field is set to 0, purchase-specific fields are ignored.
*/
$orderTotal = new BasicAmountType();
$orderTotal->currencyID = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails[0]->OrderTotal->currencyID;
$orderTotal->value = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails[0]->OrderTotal->value;
//Details about each individual item included in the order.
$itemDetails = new PaymentDetailsItemType();
$itemDetails->Name = 'sample item';
$itemDetails->Amount = $orderTotal;
$itemDetails->Quantity = '1';
/*
 * Item quantity. This field is required when you pass a value for ItemCategory. For digital goods (ItemCategory=Digital), this field is required
*/
コード例 #3
0
 /**
  * Retrieve the checkout instance from paypal
  *
  * @return \PayPalAPI\GetExpressCheckoutDetailsResponseType
  */
 public function retrieveCheckoutInfo($token)
 {
     $paypalService = new PayPalAPIInterfaceServiceService();
     $getExpressCheckoutReq = new GetExpressCheckoutDetailsReq();
     $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token);
     return $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
 }
コード例 #4
0
 function getResponse()
 {
     $token = $_GET['token'];
     $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(Configuration::getAcctAndConfig());
     try {
         /* wrap API method calls on the service object with a try catch */
         $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
     } catch (Exception $ex) {
         if (isset($ex)) {
             $ex_message = $ex->getMessage();
             $ex_type = get_class($ex);
             if ($ex instanceof PPConnectionException) {
                 $ex_detailed_message = "Error connecting to " . $ex->getUrl();
             } else {
                 if ($ex instanceof PPMissingCredentialException || $ex instanceof PPInvalidCredentialException) {
                     $ex_detailed_message = $ex->errorMessage();
                 } else {
                     if ($ex instanceof PPConfigurationException) {
                         $ex_detailed_message = "Invalid configuration. Please check your configuration file";
                     }
                 }
             }
             print_r($ex_detailed_message);
         }
         exit;
     }
     if (isset($getECResponse)) {
         $payerId = urlencode($getECResponse->GetExpressCheckoutDetailsResponseDetails->PayerInfo->PayerID);
         $paymentAction = urlencode("Sale");
         $getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token);
         $getExpressCheckoutReq = new GetExpressCheckoutDetailsReq();
         $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
         /*
         Configuration::getAcctAndConfig() returns array that contains credential and config parameters
         */
         $paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig());
         try {
             /* wrap API method calls on the service object with a try catch */
             $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
         } catch (Exception $ex) {
             if (isset($ex)) {
                 $ex_message = $ex->getMessage();
                 $ex_type = get_class($ex);
                 if ($ex instanceof PPConnectionException) {
                     $ex_detailed_message = "Error connecting to " . $ex->getUrl();
                 } else {
                     if ($ex instanceof PPMissingCredentialException || $ex instanceof PPInvalidCredentialException) {
                         $ex_detailed_message = $ex->errorMessage();
                     } else {
                         if ($ex instanceof PPConfigurationException) {
                             $ex_detailed_message = "Invalid configuration. Please check your configuration file";
                         }
                     }
                 }
                 print_r($ex_detailed_message);
             }
             exit;
         }
         //----------------------------------------------------------------------------
         /*
          * The total cost of the transaction to the buyer. If shipping cost (not applicable to digital goods) and tax charges are known, include them in this value. If not, this value should be the current sub-total of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. Set this field to 0 if the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment that is not immediately charged. When the field is set to 0, purchase-specific fields are ignored.
          */
         $orderTotal = new BasicAmountType();
         $orderTotal->currencyID = "MXN";
         $orderTotal->value = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails[0]->OrderTotal->value;
         $paymentDetails = new PaymentDetailsType();
         $paymentDetails->OrderTotal = $orderTotal;
         $DoECRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
         $DoECRequestDetails->PayerID = $payerId;
         $DoECRequestDetails->Token = $token;
         $DoECRequestDetails->PaymentAction = $paymentAction;
         $DoECRequestDetails->PaymentDetails[0] = $paymentDetails;
         $DoECRequest = new DoExpressCheckoutPaymentRequestType();
         $DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
         $DoECReq = new DoExpressCheckoutPaymentReq();
         $DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
         try {
             /* wrap API method calls on the service object with a try catch */
             $DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
         } catch (Exception $ex) {
             if (isset($ex)) {
                 $ex_message = $ex->getMessage();
                 $ex_type = get_class($ex);
                 if ($ex instanceof PPConnectionException) {
                     $ex_detailed_message = "Error connecting to " . $ex->getUrl();
                 } else {
                     if ($ex instanceof PPMissingCredentialException || $ex instanceof PPInvalidCredentialException) {
                         $ex_detailed_message = $ex->errorMessage();
                     } else {
                         if ($ex instanceof PPConfigurationException) {
                             $ex_detailed_message = "Invalid configuration. Please check your configuration file";
                         }
                     }
                 }
                 print_r($ex_detailed_message);
             }
             exit;
         }
         if (isset($DoECResponse)) {
             if (isset($DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo)) {
                 $return = array('transactionID' => $DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->TransactionID, 'total' => $DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->GrossAmount->value);
                 return $return;
             } else {
                 return false;
             }
         }
     }
 }
コード例 #5
0
 public function doExpressCheckout()
 {
     $token = urlencode($_REQUEST['token']);
     $payerId = urlencode($_REQUEST['PayerID']);
     $token = $_REQUEST['token'];
     $getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token);
     $getExpressCheckoutReq = new GetExpressCheckoutDetailsReq();
     $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
     $paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig());
     try {
         /** @var \PayPal\PayPalAPI\GetExpressCheckoutDetailsResponseType $getECResponse */
         $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
     } catch (Exception $ex) {
         echo $ex->getMessage();
     }
     $orderTotal = new BasicAmountType();
     $orderTotal->currencyID = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails[0]->OrderTotal->currencyID;
     $orderTotal->value = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails[0]->OrderTotal->value;
     //Details about each individual item included in the order.
     $itemDetails = new PaymentDetailsItemType();
     $itemDetails->Name = 'Sexy Plus Size V-Neck Short Sleeve Lace Hollow Out Dress(SKU189442)';
     $itemDetails->Amount = $orderTotal;
     $itemDetails->Quantity = '1';
     $itemDetails->ItemCategory = 'Digital';
     $PaymentDetails = new PaymentDetailsType();
     $PaymentDetails->PaymentDetailsItem[0] = $itemDetails;
     //$PaymentDetails->ShipToAddress = $address;
     $PaymentDetails->OrderTotal = $orderTotal;
     /*
      * How you want to obtain payment. When implementing parallel payments, this field is required and must be set to Order. When implementing digital goods, this field is required and must be set to Sale.
      */
     $PaymentDetails->PaymentAction = 'Sale';
     $PaymentDetails->ItemTotal = $orderTotal;
     $DoECRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
     $DoECRequestDetails->PayerID = $payerId;
     $DoECRequestDetails->Token = $token;
     $DoECRequestDetails->PaymentDetails[0] = $PaymentDetails;
     $DoECRequest = new DoExpressCheckoutPaymentRequestType();
     $DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
     $DoECReq = new DoExpressCheckoutPaymentReq();
     $DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
     $paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig());
     $DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
     //var_dump($DoECResponse);
     if ($DoECResponse->Ack == 'Success') {
         $this->successExpressCheckout();
     } else {
         echo "failed, please contact us: cservice@pandoraf.com!";
         exit;
     }
 }
コード例 #6
0
 public function _displayMessage()
 {
     $this->_autoload();
     $config = $this->getConfig();
     $token = urlencode($_REQUEST['token']);
     $payerId = urlencode($_REQUEST['PayerID']);
     //get express checkout token
     $getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(JFactory::getApplication()->input->getString('token'));
     $getExpressCheckoutReq = new GetExpressCheckoutDetailsReq();
     $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
     $paypalService = new PayPalAPIInterfaceServiceService($config);
     try {
         $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
     } catch (Exception $ex) {
         echo $ex->getMessage();
         exit;
     }
     //debug($getECResponse);die;
     //------------DO direct checkout---------------------//
     $order_number = $getECResponse->GetExpressCheckoutDetailsResponseDetails->Custom;
     $order = $this->_getOrder($order_number);
     if ($this->format_number($order->total) != $this->format_number($getECResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails[0]->OrderTotal->value)) {
         echo 'Order total is invalied';
         die;
     }
     $DoECRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
     $DoECRequestDetails->PayerID = $payerId;
     $DoECRequestDetails->Token = $token;
     $DoECRequestDetails->PaymentDetails[0] = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails[0];
     $DoECRequest = new DoExpressCheckoutPaymentRequestType();
     $DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
     $DoECReq = new DoExpressCheckoutPaymentReq();
     $DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
     /*
      * 	 ## Creating service wrapper object
     Creating service wrapper object to make API call and loading
     */
     $paypalService = new PayPalAPIInterfaceServiceService($config);
     try {
         /* wrap API method calls on the service object with a try catch */
         $DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
     } catch (Exception $ex) {
         echo $ex->getMessage();
         exit;
     }
     //		debug($paypalService);die;
     if ($DoECResponse->Ack == 'Success') {
         $order->pay_status = 'SUCCESS';
         $order->order_status = 'CONFIRMED';
         $order->tx_id = $DoECResponse->PaymentInfo[0]->TransactionID;
         $params = json_decode($order->params);
         if (empty($params)) {
             $params = new JObject();
         }
         $params->payment = new JObject();
         $params->payment->type = "paypal";
         $params->payment->number = '';
         $order->params = json_encode($params);
         $order->store();
     }
     return $order;
 }
コード例 #7
0
 /**
  * PayPal confirm OTO URL
  */
 public function getPaypalConfirmOto()
 {
     // Add third party libraries
     require_once app_path() . "/libraries/Curl/Curl.php";
     // Add Curl library
     $product = Session::get('_product');
     $plan = Session::get('_plan');
     $buyer = Session::get('_buyer');
     // Create Buyer Account
     $buyer = Buyer::where('id', '=', $buyer)->first();
     $email = $buyer->email;
     $first_name = $buyer->first_name;
     $last_name = $buyer->last_name;
     // Get product and plan data
     $product = Product::where('id', '=', $product)->first();
     $plan = Plan::where('id', '=', $plan)->first();
     $config = array('mode' => Config::get('project.paypal_mode'), 'acct1.UserName' => Config::get('project.paypal_api_username'), 'acct1.Password' => Config::get('project.paypal_api_password'), 'acct1.Signature' => Config::get('project.paypal_api_signature'));
     // Payment is charged, now create recurring profile if it is recurring product
     if ($plan->is_recurring) {
         $currencyCode = "USD";
         /*
          *  You can include up to 10 recurring payments profiles per request. The
         order of the profile details must match the order of the billing
         agreement details specified in the SetExpressCheckout request which
         takes mandatory argument:
         
         * `billing start date` - The date when billing for this profile begins.
         `Note:
         The profile may take up to 24 hours for activation.`
         */
         $RPProfileDetails = new RecurringPaymentsProfileDetailsType();
         $RPProfileDetails->SubscriberName = $first_name . ' ' . $last_name;
         //$_REQUEST['subscriberName'];
         // Y-m-d\TH:i:sP
         $time_after_30_days = time() + 86400 * 30 * $plan->recurring_freq;
         //$time_after_30_days = time();
         $billing_start_date = date(DATE_ATOM, $time_after_30_days);
         $RPProfileDetails->BillingStartDate = $billing_start_date;
         //$_REQUEST['billingStartDate'];
         //$RPProfileDetails->SubscriberShippingAddress  = $shippingAddress;
         $activationDetails = new ActivationDetailsType();
         /*
          * (Optional) Initial non-recurring payment amount due immediately upon profile creation. Use an initial amount for enrolment or set-up fees.
          */
         //$activationDetails->InitialAmount = new BasicAmountType($currencyCode, $plan->setup_fee); //$_REQUEST['initialAmount']
         /*
         			 *  (Optional) Action you can specify when a payment fails. It is one of the following values:
            ContinueOnFailure – By default, PayPal suspends the pending profile in the event that the initial payment amount fails. You can override this default behavior by setting this field to ContinueOnFailure. Then, if the initial payment amount fails, PayPal adds the failed payment amount to the outstanding balance for this recurring payment profile.
            When you specify ContinueOnFailure, a success code is returned to you in the CreateRecurringPaymentsProfile response and the recurring payments profile is activated for scheduled billing immediately. You should check your IPN messages or PayPal account for updates of the payment status.
            CancelOnFailure – If this field is not set or you set it to CancelOnFailure, PayPal creates the recurring payment profile, but places it into a pending status until the initial payment completes. If the initial payment clears, PayPal notifies you by IPN that the pending profile has been activated. If the payment fails, PayPal notifies you by IPN that the pending profile has been canceled.
         */
         //$activationDetails->FailedInitialAmountAction = $_REQUEST['failedInitialAmountAction'];
         /*
          *  Regular payment period for this schedule which takes mandatory
         params:
         
         * `Billing Period` - Unit for billing during this subscription period. It is one of the
         following values:
         * Day
         * Week
         * SemiMonth
         * Month
         * Year
         For SemiMonth, billing is done on the 1st and 15th of each month.
         `Note:
         The combination of BillingPeriod and BillingFrequency cannot exceed
         one year.`
         * `Billing Frequency` - Number of billing periods that make up one billing cycle.
         The combination of billing frequency and billing period must be less
         than or equal to one year. For example, if the billing cycle is
         Month, the maximum value for billing frequency is 12. Similarly, if
         the billing cycle is Week, the maximum value for billing frequency is
         52.
         `Note:
         If the billing period is SemiMonth, the billing frequency must be 1.`
         * `Billing Amount`
         */
         $paymentBillingPeriod = new BillingPeriodDetailsType();
         $paymentBillingPeriod->BillingFrequency = $plan->recurring_freq;
         //$_REQUEST['billingFrequency'];
         $paymentBillingPeriod->BillingPeriod = 'Month';
         //$_REQUEST['billingPeriod'];
         //$paymentBillingPeriod->TotalBillingCycles = $_REQUEST['totalBillingCycles'];
         $paymentBillingPeriod->Amount = new BasicAmountType($currencyCode, $plan->price);
         //$_REQUEST['paymentAmount']
         //$paymentBillingPeriod->ShippingAmount = new BasicAmountType($currencyCode, $_REQUEST['paymentShippingAmount']);
         //$paymentBillingPeriod->TaxAmount = new BasicAmountType($currencyCode, $_REQUEST['paymentTaxAmount']);
         /*
          * 	 Describes the recurring payments schedule, including the regular
         payment period, whether there is a trial period, and the number of
         payments that can fail before a profile is suspended which takes
         mandatory params:
         
         * `Description` - Description of the recurring payment.
         `Note:
         You must ensure that this field matches the corresponding billing
         agreement description included in the SetExpressCheckout request.`
         * `Payment Period`
         */
         $scheduleDetails = new ScheduleDetailsType();
         $scheduleDetails->Description = $product->name . " - " . $plan->name;
         //$_REQUEST['profileDescription'];
         $scheduleDetails->ActivationDetails = $activationDetails;
         // if( $_REQUEST['trialBillingFrequency'] != "" && $_REQUEST['trialAmount'] != "") {
         // 	$trialBillingPeriod =  new BillingPeriodDetailsType();
         // 	$trialBillingPeriod->BillingFrequency = $_REQUEST['trialBillingFrequency'];
         // 	$trialBillingPeriod->BillingPeriod = $_REQUEST['trialBillingPeriod'];
         // 	$trialBillingPeriod->TotalBillingCycles = $_REQUEST['trialBillingCycles'];
         // 	$trialBillingPeriod->Amount = new BasicAmountType($currencyCode, $_REQUEST['trialAmount']);
         // 	$trialBillingPeriod->ShippingAmount = new BasicAmountType($currencyCode, $_REQUEST['trialShippingAmount']);
         // 	$trialBillingPeriod->TaxAmount = new BasicAmountType($currencyCode, $_REQUEST['trialTaxAmount']);
         // 	$scheduleDetails->TrialPeriod  = $trialBillingPeriod;
         // }
         $scheduleDetails->PaymentPeriod = $paymentBillingPeriod;
         // $scheduleDetails->MaxFailedPayments =  $_REQUEST['maxFailedPayments'];
         // $scheduleDetails->AutoBillOutstandingAmount = $_REQUEST['autoBillOutstandingAmount'];
         /*
          * 	 `CreateRecurringPaymentsProfileRequestDetailsType` which takes
         mandatory params:
         
         * `Recurring Payments Profile Details`
         * `Schedule Details`
         */
         $createRPProfileRequestDetail = new CreateRecurringPaymentsProfileRequestDetailsType();
         if (trim($_REQUEST['token']) != "") {
             $createRPProfileRequestDetail->Token = $_REQUEST['token'];
         }
         $createRPProfileRequestDetail->ScheduleDetails = $scheduleDetails;
         $createRPProfileRequestDetail->RecurringPaymentsProfileDetails = $RPProfileDetails;
         $createRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
         $createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetail;
         $createRPProfileReq = new CreateRecurringPaymentsProfileReq();
         $createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;
         /*
          *  ## 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($config);
         try {
             /* wrap API method calls on the service object with a try catch */
             $createRPProfileResponse = $paypalService->CreateRecurringPaymentsProfile($createRPProfileReq);
         } catch (Exception $ex) {
             echo "Error occured while charging for PayPal. Please try again later";
             exit;
         }
         if (isset($createRPProfileResponse)) {
             /*echo "<table>";
             				echo "<tr><td>Ack :</td><td><div id='Ack'>$createRPProfileResponse->Ack</div> </td></tr>";
             				echo "<tr><td>ProfileID :</td><td><div id='ProfileID'>".$createRPProfileResponse->CreateRecurringPaymentsProfileResponseDetails->ProfileID ."</div> </td></tr>";
             				echo "</table>";
             
             				echo "<pre>";
             				print_r($createRPProfileResponse);
             				echo "</pre>";*/
             if (!empty($createRPProfileResponse->Ack) and $createRPProfileResponse->Ack == 'Success') {
                 if ($createRPProfileResponse->CreateRecurringPaymentsProfileResponseDetails->ProfileStatus == 'ActiveProfile') {
                     $paypal_sub_id = $createRPProfileResponse->CreateRecurringPaymentsProfileResponseDetails->ProfileID;
                 } else {
                     echo "Error occured while charging for PayPal. Please try again later";
                     exit;
                 }
             } else {
                 echo "Error occured while charging for PayPal. Please try again later";
                 exit;
             }
         } else {
             echo "Error occured while charging for PayPal. Please try again later";
             exit;
         }
     }
     /*
      * The DoExpressCheckoutPayment API operation completes an Express Checkout transaction. If you set up a billing agreement in your SetExpressCheckout API call, the billing agreement is created when you call the DoExpressCheckoutPayment API operatio
      */
     /*
      * The total cost of the transaction to the buyer. If shipping cost (not applicable to digital goods) and tax charges are known, include them in this value. If not, this value should be the current sub-total of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. Set this field to 0 if the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment that is not immediately charged. When the field is set to 0, purchase-specific fields are ignored.
      * For digital goods, the following must be true:
      * total cost > 0
      * total cost <= total cost passed in the call to SetExpressCheckout
      */
     $token = urlencode($_REQUEST['token']);
     /*
      *  Unique PayPal buyer account identification number as returned in the GetExpressCheckoutDetails response
      */
     $payerId = urlencode($_REQUEST['PayerID']);
     $paymentAction = "Sale";
     //urlencode(  $_REQUEST['paymentAction']);
     // ------------------------------------------------------------------
     // this section is optional if parameters required for DoExpressCheckout is retrieved from your database
     $getExpressCheckoutDetailsRequest = new PayPal\PayPalAPI\GetExpressCheckoutDetailsRequestType($token);
     $getExpressCheckoutReq = new PayPal\PayPalAPI\GetExpressCheckoutDetailsReq();
     $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
     // ------------------------------------------------------------------
     // this section get checkout data from PayPal
     $getExpressCheckoutDetailsRequest = new PayPal\PayPalAPI\GetExpressCheckoutDetailsRequestType($token);
     $getExpressCheckoutReq = new PayPal\PayPalAPI\GetExpressCheckoutDetailsReq();
     $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
     /*
     Configuration::getAcctAndConfig() returns array that contains credential and config parameters
     */
     $paypalService = new PayPal\Service\PayPalAPIInterfaceServiceService($config);
     try {
         /* wrap API method calls on the service object with a try catch */
         $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
     } catch (Exception $ex) {
         echo "Error occured while charging for PayPal";
         exit;
     }
     //----------------------------------------------------------------------------
     try {
         /* wrap API method calls on the service object with a try catch */
         $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
     } catch (Exception $ex) {
         echo "Error occured while charging for PayPal";
         exit;
     }
     if (isset($getECResponse)) {
         $amount = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails[0]->OrderTotal->value;
     }
     /*
      * The total cost of the transaction to the buyer. If shipping cost (not applicable to digital goods) and tax charges are known, include them in this value. If not, this value should be the current sub-total of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. Set this field to 0 if the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment that is not immediately charged. When the field is set to 0, purchase-specific fields are ignored.
      */
     $orderTotal = new PayPal\CoreComponentTypes\BasicAmountType();
     $orderTotal->currencyID = 'USD';
     $orderTotal->value = $amount;
     //$_REQUEST['amt'];
     $paymentDetails = new PayPal\EBLBaseComponents\PaymentDetailsType();
     $paymentDetails->OrderTotal = $orderTotal;
     /*
      * Your URL for receiving Instant Payment Notification (IPN) about this transaction. If you do not specify this value in the request, the notification URL from your Merchant Profile is used, if one exists.
      */
     $paymentDetails->NotifyURL = Config::get('project.paypal_ipn_url');
     $DoECRequestDetails = new PayPal\EBLBaseComponents\DoExpressCheckoutPaymentRequestDetailsType();
     $DoECRequestDetails->PayerID = $payerId;
     $DoECRequestDetails->Token = $token;
     $DoECRequestDetails->PaymentAction = $paymentAction;
     $DoECRequestDetails->PaymentDetails[0] = $paymentDetails;
     $DoECRequest = new PayPal\PayPalAPI\DoExpressCheckoutPaymentRequestType();
     $DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
     $DoECReq = new PayPal\PayPalAPI\DoExpressCheckoutPaymentReq();
     $DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
     try {
         /* wrap API method calls on the service object with a try catch */
         $DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
     } catch (Exception $ex) {
         echo "Error occured while charging for PayPal";
         exit;
     }
     if (isset($DoECResponse)) {
         // Get Transaction ID
         if (!empty($DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->TransactionID)) {
             $transaction_id = $DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->TransactionID;
         } else {
             Log::info('PayPal EC Confirm failed', array('buyer' => $buyer, 'product' => $product->id, 'plan' => $plan->id, 'COData' => $DoECResponse));
             // Redirect back them to PayPal with token
             return Redirect::to(Config::get('project.paypal_api_url') . 'cgi-bin/webscr?cmd=_express-checkout&token=' . trim($_REQUEST['token']));
         }
         // Update Buyer IP
         Buyer::updateLastIP($buyer);
         // Get Purchase ID
         $purchase = Purchase::where('product_id', '=', $product->id)->where('buyer_id', '=', $buyer->id)->first();
         // If we successfully get the recurring ID
         if (!empty($paypal_sub_id)) {
             $purchase->paypal_sub_id = $paypal_sub_id;
             $purchase->save();
         }
         // Push data using own IPN
         $ipn_url = Config::get('project.paypal_ipn_url');
         $data_curl = array("dk_new_charge" => TRUE, "transaction_id" => $transaction_id, "buyer_id" => $buyer->id, "plan_id" => $plan->id, "product_id" => $product->id, "amount" => $amount);
         $curl = new Curl();
         $curl->simple_post($ipn_url, $data_curl, array(CURLOPT_BUFFERSIZE => 10));
         // Everything is ok, now remove session data
         // for security purpose
         Session::forget('_product');
         Session::forget('_plan');
         Session::forget('_buyer');
         // Redirect
         $url = url('checkout/thanks?url=' . $plan->next_page_url . '&code=' . $product->code);
         return Redirect::to($url);
         //return Redirect::to($plan->next_page_url);
     }
 }
コード例 #8
0
ファイル: PayPalApiService.php プロジェクト: TonyWoo/website
 /**
  * Retrieve the checkout instance from paypal
  *
  * @param string $token
  * @return boolean
  */
 public function retrieveCheckoutInfo($token)
 {
     $paypalService = new PayPalAPIInterfaceServiceService();
     $getExpressCheckoutReq = new GetExpressCheckoutDetailsReq();
     $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token);
     $response = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
     return isset($response) && $response->Ack == 'Success';
 }
コード例 #9
0
 /**
  * Purchase Paypal Response
  * @param Request $request
  * @return $this
  */
 public function purchasePaypalResponse(Request $request)
 {
     $config = array('mode' => $this->modeApiPaypal, 'acct1.UserName' => $this->userApiPaypal, 'acct1.Password' => $this->passwordApiPaypal, 'acct1.Signature' => $this->signatureApiPaypal);
     //getExpressCheckout
     $getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($request->token);
     $getExpressCheckoutReq = new GetExpressCheckoutDetailsReq();
     $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
     $paypalService = new PayPalAPIInterfaceServiceService($config);
     $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
     //DoExpressCheckout
     $DoECRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
     $DoECRequestDetails->PayerID = $request->PayerID;
     $DoECRequestDetails->Token = $request->token;
     $DoECRequestDetails->PaymentDetails[0] = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails[0];
     //$DoECRequestDetails->PaymentAction = "Sale";
     $DoECRequest = new DoExpressCheckoutPaymentRequestType();
     $DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
     $DoECReq = new DoExpressCheckoutPaymentReq();
     $DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
     $DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
     $purchaseOperationNumber = "";
     //dd($DoECResponse);
     list($product, $items, $total) = $this->getPurchasedOptions($getECResponse->GetExpressCheckoutDetailsResponseDetails->Custom);
     if ($DoECResponse->Ack == 'Success') {
         $purchaseOperationNumber = $DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->TransactionID;
         //guardamos la operacion en db si no existe ya el mismo numero de operación
         $exitsPayment = $this->paymentRepository->findByOperationNumber($purchaseOperationNumber);
         if (!$exitsPayment) {
             $payment = $this->paymentRepository->store(['product_id' => $product->id, 'purchaseOperationNumber' => $purchaseOperationNumber]);
         }
         //actualizamos el estado del producto recien ingresado a publicado
         $this->productRepository->update_state($product->id, 1);
         // 0:inactivo 1:publicado 2:en espera 3:inactivo(pago rechazado o denegado)
         // informamos via email del producto recien creado y su confirmacion de pago
         try {
             $this->mailer->paymentConfirmation(['email' => Auth()->user()->email, 'product' => $product, 'items' => $items, 'total' => $total]);
         } catch (Swift_RfcComplianceException $e) {
             Log::error($e->getMessage());
         }
     } else {
         //actualizamos el estado del producto recien ingresado inactivo si el pago fue denegado
         $this->productRepository->update_state($product->id, 3);
         // 0:inactivo 1:publicado 2:en espera 3:inactivo(pago rechazado o denegado)
     }
     $authorizationResult = $DoECResponse->Ack;
     Log::info('results of PAYPAL: ' . json_encode($DoECResponse));
     return view('products.purchase-response')->with(compact('items', 'total', 'authorizationResult', 'purchaseOperationNumber'));
 }