PayPal\Service\PayPalAPIInterfaceServiceService::SetExpressCheckout PHP Method

SetExpressCheckout() public method

Service Call: SetExpressCheckout
public SetExpressCheckout ( SetExpressCheckoutReq $setExpressCheckoutReq, mixed $apiCredential = null ) : SetExpressCheckoutResponseType
$setExpressCheckoutReq PayPal\PayPalAPI\SetExpressCheckoutReq
$apiCredential mixed - Optional API credential - can either be a username configured in sdk_config.ini or a ICredential object created dynamically
return PayPal\PayPalAPI\SetExpressCheckoutResponseType
    public function SetExpressCheckout($setExpressCheckoutReq, $apiCredential = null)
    {
        $apiContext = new PPApiContext($this->config);
        $handlers = array(new PPMerchantServiceHandler($apiCredential, self::$SDK_NAME, self::$SDK_VERSION));
        $this->setStandardParams($setExpressCheckoutReq->SetExpressCheckoutRequest);
        $ret = new SetExpressCheckoutResponseType();
        $resp = $this->call('PayPalAPIAA', 'SetExpressCheckout', $setExpressCheckoutReq, $apiContext, $handlers);
        $ret->init(PPUtils::xmlToArray($resp));
        return $ret;
    }

Usage Example

Example #1
0
 public function makePayment(Payment $payment, $data = [])
 {
     $payPalCustom = md5($payment->getId() . '-' . time());
     $payPalTransaction = new PaypalTransaction();
     $payPalTransaction->setAmount($payment->getCreditAmount())->setDonationAmount($payment->getDonationAmount())->setPaypalTransactionFee($payment->getTransactionFee())->setTotalAmount($payment->getTotalAmount())->setStatus('START')->setCustom($payPalCustom)->setPaymentId($payment->getId());
     $payPalTransaction->save();
     $paymentDetail = $this->setPaypalCheckoutCart($payment);
     $expressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
     $expressCheckoutRequestDetails->Custom = $payPalCustom;
     $expressCheckoutRequestDetails->PaymentDetails = $paymentDetail;
     $expressCheckoutRequestDetails->CancelURL = action('PayPalController@getCancel');
     $expressCheckoutRequestDetails->ReturnURL = action('PayPalController@getReturn');
     // Display options
     $expressCheckoutRequestDetails->cpplogoimage = 'https://www.zidisha.org/static/images/logo/zidisha-logo-small.png';
     $expressCheckoutRequestDetails->BrandName = 'Zidisha';
     //Shipping options if required.
     $expressCheckoutRequestDetails->NoShipping = 1;
     $expressCheckoutRequestDetails->ReqConfirmShipping = 0;
     //Set and configure express checkout
     $setExpressCheckoutRequestType = new SetExpressCheckoutRequestType();
     $setExpressCheckoutRequestType->SetExpressCheckoutRequestDetails = $expressCheckoutRequestDetails;
     $setExpressCheckoutRequest = new SetExpressCheckoutReq();
     $setExpressCheckoutRequest->SetExpressCheckoutRequest = $setExpressCheckoutRequestType;
     try {
         //Try Express Checkout.
         $setExpressCheckoutResponse = $this->payPalApi->SetExpressCheckout($setExpressCheckoutRequest);
     } catch (PPConnectionException $e) {
         $paymentError = new PaymentError('Error Connecting to PayPal.', $e);
         return $this->paymentBus->getFailedHandler($payment, $paymentError)->redirect();
     }
     //Check if we get a Successful acknowledgment from the server.
     if ($setExpressCheckoutResponse->Ack != 'Success') {
         $this->logPayPalErrors($payment, $setExpressCheckoutResponse);
         $paymentError = new PaymentError('Error Connecting to PayPal.');
         return $this->paymentBus->getFailedHandler($payment, $paymentError)->redirect();
     }
     $payPalTransaction->setToken($setExpressCheckoutResponse->Token);
     $payPalTransaction->save();
     $paypalUrl = 'https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=' . $setExpressCheckoutResponse->Token;
     return \Redirect::away($paypalUrl);
 }
All Usage Examples Of PayPal\Service\PayPalAPIInterfaceServiceService::SetExpressCheckout