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
Exemplo n.º 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);
 }
Exemplo n.º 2
0
 function sendToPaypal()
 {
     //Payment details
     $this->paymentDetails->ShipToAddress = $this->address;
     $this->paymentDetails->ItemTotal = new BasicAmountType($this->currencyCode, $this->itemTotalValue);
     //$paymentDetails->TaxTotal = new BasicAmountType($currencyCode, $taxTotalValue);
     $this->paymentDetails->OrderTotal = new BasicAmountType($this->currencyCode, $this->orderTotalValue);
     /*
     		 * 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. If the transaction does not include a one-time purchase, this field is ignored. It is one of the following values:
        Sale � This is a final sale for which you are requesting payment (default).
        Authorization � This payment is a basic authorization subject to settlement with PayPal Authorization and Capture.
        Order � This payment is an order authorization subject to settlement with PayPal Authorization and Capture.
     */
     $this->paymentDetails->PaymentAction = "Sale";
     //$paymentDetails->HandlingTotal = $handlingTotal;
     //$paymentDetails->InsuranceTotal = $insuranceTotal;
     //$paymentDetails->ShippingTotal = $shippingTotal;
     $setECReqDetails = new SetExpressCheckoutRequestDetailsType();
     $setECReqDetails->PaymentDetails[0] = $this->paymentDetails;
     /*
      * (Required) URL to which the buyer is returned if the buyer does not approve the use of PayPal to pay you. For digital goods, you must add JavaScript to this page to close the in-context experience.
      */
     $setECReqDetails->CancelURL = $this->cancelUrl;
     /*
      * (Required) URL to which the buyer's browser is returned after choosing to pay with PayPal. For digital goods, you must add JavaScript to this page to close the in-context experience.
      */
     $setECReqDetails->ReturnURL = $this->returnUrl;
     /*
     		 * Determines where or not PayPal displays shipping address fields on the PayPal pages. For digital goods, this field is required, and you must set it to 1. It is one of the following values:
        0 � PayPal displays the shipping address on the PayPal pages.
        1 � PayPal does not display shipping address fields whatsoever.
        2 � If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
     */
     $setECReqDetails->NoShipping = 0;
     /*
     		 *  (Optional) Determines whether or not the PayPal pages should display the shipping address set by you in this SetExpressCheckout request, not the shipping address on file with PayPal for this buyer. Displaying the PayPal street address on file does not allow the buyer to edit that address. It is one of the following values:
        0 � The PayPal pages should not display the shipping address.
        1 � The PayPal pages should display the shipping address.
     */
     $setECReqDetails->AddressOverride = 1;
     /*
     		 * Indicates whether or not you require the buyer's shipping address on file with PayPal be a confirmed address. For digital goods, this field is required, and you must set it to 0. It is one of the following values:
        0 � You do not require the buyer's shipping address be a confirmed address.
        1 � You require the buyer's shipping address be a confirmed address.
     */
     $setECReqDetails->ReqConfirmShipping = 1;
     // Billing agreement details
     $billingAgreementDetails = new BillingAgreementDetailsType("None");
     $billingAgreementDetails->BillingAgreementDescription = "Un solo pago";
     $setECReqDetails->BillingAgreementDetails = array($billingAgreementDetails);
     // Display options
     $setECReqDetails->cppheaderimage = "http://www.plazadelatecnologia.com/assets/graphics/paypal-plazadelatecnologia.png";
     //$setECReqDetails->cppheaderbordercolor = $_REQUEST['cppheaderbordercolor'];
     //$setECReqDetails->cppheaderbackcolor = $_REQUEST['cppheaderbackcolor'];
     //$setECReqDetails->cpppayflowcolor = $_REQUEST['cpppayflowcolor'];
     //$setECReqDetails->cppcartbordercolor = $_REQUEST['cppcartbordercolor'];
     //$setECReqDetails->cpplogoimage = $_REQUEST['cpplogoimage'];
     //$setECReqDetails->PageStyle = $_REQUEST['pageStyle'];
     //$setECReqDetails->BrandName = $_REQUEST['brandName'];
     // Advanced options
     $setECReqDetails->AllowNote = 1;
     $setECReqType = new SetExpressCheckoutRequestType();
     $setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
     $setECReq = new SetExpressCheckoutReq();
     $setECReq->SetExpressCheckoutRequest = $setECReqType;
     /*
      * 	 ## 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 */
         $setECResponse = $paypalService->SetExpressCheckout($setECReq);
     } 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($setECResponse) && $setECResponse->Ack == 'Success') {
         $token = $setECResponse->Token;
         // Redirect to paypal.com here
         $payPalURL = 'https://www.paypal.com/webscr?cmd=_express-checkout&token=' . $token;
         redirect($payPalURL);
     } else {
         echo "<table>";
         echo "<tr><td>Ack :</td><td><div id='Ack'>{$setECResponse->Ack}</div> </td></tr>";
         echo "<tr><td>Token :</td><td><div id='Token'>{$setECResponse->Token}</div> </td></tr>";
         echo "</table>";
         echo '<pre>';
         print_r($setECResponse);
         echo '</pre>';
     }
 }
Exemplo n.º 3
0
 /**
  * Execute the setExpressCheckout process, forwards to paypal
  *
  * @param array $order          
  * @param array $subscription         
  * @param bool $recurring         
  */
 public function createECResponse($responseUrl, array $order, array $subscriptionType, $recurring = false)
 {
     // @todo should pass these urls in
     $returnUrl = Http::getBaseUrl() . $responseUrl . '?success=true&orderId=' . urlencode($order['orderId']);
     $cancelUrl = Http::getBaseUrl() . $responseUrl . '?success=false&orderId=' . urlencode($order['orderId']);
     $setECReqDetails = new SetExpressCheckoutRequestDetailsType();
     $setECReqDetails->ReqConfirmShipping = 0;
     $setECReqDetails->NoShipping = 1;
     $setECReqDetails->AllowNote = 0;
     $setECReqDetails->ReturnURL = $returnUrl;
     $setECReqDetails->CancelURL = $cancelUrl;
     $setECReqDetails->SolutionType = 'Sole';
     if ($recurring) {
         // Create billing agreement for recurring payment
         $billingAgreementDetails = new BillingAgreementDetailsType('RecurringPayments');
         $billingAgreementDetails->BillingAgreementDescription = $subscriptionType['agreement'];
         $setECReqDetails->BillingAgreementDetails[0] = $billingAgreementDetails;
     }
     $paymentDetails = new PaymentDetailsType();
     $paymentDetails->PaymentAction = 'Sale';
     $paymentDetails->NotifyURL = Config::$a['paypal']['api']['ipn'];
     $paymentDetails->OrderTotal = new BasicAmountType($order['currency'], $order['amount']);
     $paymentDetails->ItemTotal = new BasicAmountType($order['currency'], $order['amount']);
     $paymentDetails->Recurring = 0;
     $itemDetails = new PaymentDetailsItemType();
     $itemDetails->Name = $subscriptionType['itemLabel'];
     $itemDetails->Amount = new BasicAmountType($order['currency'], $order['amount']);
     $itemDetails->Quantity = 1;
     // TODO this should be 'Digital' but Paypal requires you to change your account to a digital good account, which is a las
     $itemDetails->ItemCategory = 'Physical';
     $itemDetails->Number = $subscriptionType['id'];
     $paymentDetails->PaymentDetailsItem[0] = $itemDetails;
     $setECReqDetails->PaymentDetails[0] = $paymentDetails;
     // Paypal UI settings
     $setECReqDetails->BrandName = Config::$a['commerce']['reciever']['brandName'];
     // Execute checkout
     $setECReqType = new SetExpressCheckoutRequestType();
     $setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
     $setECReq = new SetExpressCheckoutReq();
     $setECReq->SetExpressCheckoutRequest = $setECReqType;
     $paypalService = new PayPalAPIInterfaceServiceService();
     return $paypalService->SetExpressCheckout($setECReq);
 }
Exemplo n.º 4
0
   1 � PayPal does not display shipping address fields whatsoever.
   2 � If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
*/
$setECReqDetails->NoShipping = 1;
$setECReqType = new SetExpressCheckoutRequestType();
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReq = new SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
// storing in session to use in DoExpressCheckout
$_SESSION['amount'] = $_REQUEST['amount'];
$_SESSION['currencyID'] = $_REQUEST['currencyId'];
/*
 * 	 ## 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());
$setECResponse = $paypalService->SetExpressCheckout($setECReq);
// echo '<pre>';
//print_r($setECResponse);
// echo '</pre>';
if ($setECResponse->Ack == 'Success') {
    $token = $setECResponse->Token;
    /*
    		$payPalURL = 'https://www.sandbox.paypal.com/incontext?token=' . $token;
    	header("Location: ".$payPalURL);*/
    echo "<br><br><br><br><br><br><br><br><a href=https://www.sandbox.paypal.com/incontext?token={$token} />Click here to continue to https://www.sandbox.paypal.com/incontext?token={$token}</a>";
} else {
    var_dump($setECResponse);
    echo "error in SetEC API call";
}
Exemplo n.º 5
0
 /**
  * @desc 设置paypal支付信息
  * @author HollenMok 2016-04-30
  */
 public function setExpressCheckout()
 {
     //需要从session中取用户信息
     $customers_id = '2016042101';
     $productData = $this->shopcartModuleShopcart->shopcartQuery->getCartInfo($customers_id);
     $serverName = $_SERVER['SERVER_NAME'];
     $serverPort = $_SERVER['SERVER_PORT'];
     $url = dirname('http://' . $serverName . ':' . $serverPort . $_SERVER['REQUEST_URI']);
     $returnUrl = $url . "/index.php?com=shopcart&t=doExpressCheckout";
     $cancelUrl = $url . "/index.php";
     $orderTotal = new BasicAmountType();
     $orderTotal->currencyID = USD;
     //必须为两位小数
     $orderTotal->value = round($productData[0]['final_price'], 2);
     $taxTotal = new BasicAmountType();
     $taxTotal->currencyID = 'USD';
     $taxTotal->value = '0.0';
     $itemDetails = new PaymentDetailsItemType();
     $itemDetails->Name = 'Sexy Plus Size V-Neck Short Sleeve Lace Hollow Out Dress(SKU189442)';
     $itemDetails->Amount = $orderTotal;
     $itemDetails->Quantity = $productData[0]['customers_basket_quantity'];
     $itemDetails->ItemCategory = 'Digital';
     $PaymentDetails = new PaymentDetailsType();
     $PaymentDetails->PaymentDetailsItem[0] = $itemDetails;
     $orderTotalValue = $itemDetails->Quantity * round($productData[0]['final_price'], 2);
     $itemTotalValue = $itemDetails->Quantity * round($productData[0]['final_price'], 2);
     $currencyCode = 'USD';
     $paymentDetails->ItemTotal = new BasicAmountType($currencyCode, $itemTotalValue);
     $PaymentDetails->OrderTotal = new BasicAmountType($currencyCode, $orderTotalValue);
     //$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';
     /*
      * Sum of cost of all items in this order. For digital goods, this field is required.
      */
     //$PaymentDetails->ItemTotal = $orderTotal;
     //$PaymentDetails->TaxTotal = $taxTotal;
     $setECReqDetails = new SetExpressCheckoutRequestDetailsType();
     $setECReqDetails->BrandName = "pandoraf.com";
     $setECReqDetails->PaymentDetails[0] = $PaymentDetails;
     $setECReqDetails->CancelURL = $cancelUrl;
     $setECReqDetails->ReturnURL = $returnUrl;
     $setECReqDetails->ReqConfirmShipping = 0;
     $setECReqDetails->NoShipping = 1;
     $setECReqType = new SetExpressCheckoutRequestType();
     $setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
     $setECReq = new SetExpressCheckoutReq();
     $setECReq->SetExpressCheckoutRequest = $setECReqType;
     $paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig());
     $setECResponse = $paypalService->SetExpressCheckout($setECReq);
     if ($setECResponse->Ack == 'Success') {
         $token = $setECResponse->Token;
         $payPalURL = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' . $token;
         header("Location: " . $payPalURL);
         exit;
     } else {
         var_dump($setECResponse);
         echo "error in SetEC API call";
     }
 }
 function _prePayment($data)
 {
     $data['total'] = $this->format_number($data['total']);
     $this->_autoload();
     $returnUrl = JURI::root() . "index.php?option=com_bookpro&controller=payment&task=postpayment&paction=display_message&method=" . $this->_element . "&order_number=" . $data['order_number'];
     $cancelUrl = JURI::root() . "index.php?option=com_bookpro&controller=payment&task=postpayment&paction=cancel&method=" . $this->_element . "&order_number=" . $data['order_number'];
     $notify = JURI::root() . "index.php?option=com_bookpro&controller=payment&task=postpayment&paction=process&method=" . $this->_element . "&order_number=" . $data['order_number'];
     $config = $this->getConfig();
     $paypalService = new PayPalAPIInterfaceServiceService($config);
     $paymentDetails = new PaymentDetailsType();
     $itemDetails = new PaymentDetailsItemType();
     $itemDetails->Name = $data['order_number'];
     $itemDetails->Amount = $data['total'];
     $itemDetails->Quantity = 1;
     $paymentDetails->PaymentDetailsItem[0] = $itemDetails;
     $paymentDetails->Custom = $data['order_number'];
     $orderTotal = new BasicAmountType();
     $orderTotal->currencyID = $this->currency;
     $orderTotal->value = $data['total'];
     $paymentDetails->OrderTotal = $orderTotal;
     $paymentDetails->PaymentAction = 'Sale';
     $paymentDetails->NotifyURL = $notify;
     $setECReqDetails = new SetExpressCheckoutRequestDetailsType();
     $setECReqDetails->PaymentDetails[0] = $paymentDetails;
     $setECReqDetails->CancelURL = $cancelUrl;
     $setECReqDetails->ReturnURL = $returnUrl;
     $setECReqDetails->SolutionType = 'Sole';
     $setECReqDetails->LandingPage = 'Billing';
     $lang = JFactory::getLanguage();
     $local = substr($lang->getTag(), 3, 2);
     $setECReqDetails->LocaleCode = $local;
     $setECReqType = new SetExpressCheckoutRequestType();
     $setECReqType->Version = '104.0';
     $setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
     $setECReq = new SetExpressCheckoutReq();
     $setECReq->SetExpressCheckoutRequest = $setECReqType;
     try {
         /* wrap API method calls on the service object with a try catch */
         $setECResponse = $paypalService->SetExpressCheckout($setECReq);
     } catch (Exception $ex) {
         echo $ex->getMessage();
         exit;
     }
     JFactory::getApplication()->redirect($this->_getPostUrl($setECResponse->Token));
     return;
 }
 /**
  * Post OTO for paypal
  */
 public function postPaypalOto()
 {
     $product_id = Input::get('product_id');
     $plan_id = Input::get('plan_id');
     $buyer_id = Input::get('buyer_id');
     $product = Product::where('id', '=', $product_id)->first();
     $plan = Plan::where('id', '=', $plan_id)->first();
     $buyer = Buyer::where('id', '=', $buyer_id)->first();
     // $plan->price $plan->name  $plan->id
     // PayPal SetExpressCheckout
     $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'));
     /*
      * The SetExpressCheckout API operation initiates an Express Checkout transaction
      * This sample code uses Merchant PHP SDK to make API call
      */
     $returnUrl = url("checkout/paypal-confirm-oto");
     //"http://secure.digitalkickstart.com/checkout/paypal-confirm-oto";
     $cancelUrl = url("checkout/paypal-cancel");
     //"http://secure.digitalkickstart.com/checkout/paypal-cancel";
     $currencyCode = 'USD';
     $orderTotal = $plan->price + $plan->setup_fee;
     // If recurring then process manually without PayPal Merchant SDK
     if ($plan->is_recurring) {
         // For Recurring
         $ecRequestParams = array('USER' => Config::get('project.paypal_api_username'), 'PWD' => Config::get('project.paypal_api_password'), 'SIGNATURE' => Config::get('project.paypal_api_signature'), 'VERSION' => '109.0', 'METHOD' => 'SetExpressCheckout', 'RETURNURL' => $returnUrl, 'CANCELURL' => $cancelUrl, 'PAYMENTREQUEST_0_AMT' => $orderTotal, 'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD', 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', 'REQCONFIRMSHIPPING' => 0, 'NOSHIPPING' => 1, 'PROFILESTARTDATE' => date(DATE_ATOM, time() + 86400 * 30 * $plan->recurring_freq), 'L_BILLINGTYPE0' => 'RecurringPayments', 'L_BILLINGAGREEMENTDESCRIPTION0' => $product->name . " - " . $plan->name, 'PAYMENTREQUEST_0_CUSTOM' => 'RecurringPayment');
         $ecRequestParams = http_build_query($ecRequestParams);
         $curl = new Curl();
         $api_url = "https://api-3t.paypal.com/nvp?";
         if (Config::get('project.paypal_mode') == 'sandbox') {
             $api_url = "https://api-3t.sandbox.paypal.com/nvp?";
         }
         $api_url = $api_url . $ecRequestParams;
         $curl->ssl(false);
         $response = $curl->simple_get($api_url);
         $data = array();
         $key = explode('&', $response);
         if (is_array($key)) {
             foreach ($key as $temp) {
                 $keyval = explode('=', $temp);
                 if (isset($keyval[1])) {
                     $data[$keyval[0]] = $keyval[1];
                 }
             }
         }
         if (!empty($data['TOKEN'])) {
             $token = $data['TOKEN'];
             $payPalURL = Config::get('project.paypal_api_url') . "webscr?cmd=_express-checkout&token={$token}&useraction=commit";
             // Store Data in session
             Session::put('_product', $product_id);
             Session::put('_plan', $plan_id);
             Session::put('_buyer', $buyer_id);
             return Response::make(json_encode(array("success" => true, "url" => $payPalURL)));
         }
         Session::flash('error', "Payment processing error");
         return json_encode(array("error" => true, "message" => "Payment processing error"));
     }
     // details about payment
     $paymentDetails = new PayPal\EBLBaseComponents\PaymentDetailsType();
     // total order amount
     $paymentDetails->OrderTotal = new PayPal\CoreComponentTypes\BasicAmountType($currencyCode, $orderTotal);
     $paymentDetails->PaymentAction = 'Sale';
     $paymentDetails->Custom = $plan->id;
     $paymentDetails->OrderDescription = $product->name . " - " . $plan->name;
     $itemDetails = new PayPal\EBLBaseComponents\PaymentDetailsItemType();
     $itemDetails->Name = $product->name . " - " . $plan->name;
     $itemDetails->Amount = $orderTotal;
     $paymentDetails->PaymentDetailsItem[0] = $itemDetails;
     $setECReqDetails = new PayPal\EBLBaseComponents\SetExpressCheckoutRequestDetailsType();
     $setECReqDetails->PaymentDetails[0] = $paymentDetails;
     /*
      * (Required) URL to which the buyer is returned if the buyer does not approve the use of PayPal to pay you. For digital goods, you must add JavaScript to this page to close the in-context experience.
      */
     $setECReqDetails->CancelURL = $cancelUrl;
     /*
      * (Required) URL to which the buyer's browser is returned after choosing to pay with PayPal. For digital goods, you must add JavaScript to this page to close the in-context experience.
      */
     $setECReqDetails->ReturnURL = $returnUrl;
     $setECReqDetails->NoShipping = TRUE;
     $setECReqType = new PayPal\PayPalAPI\SetExpressCheckoutRequestType();
     $setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
     $setECReq = new PayPal\PayPalAPI\SetExpressCheckoutReq();
     $setECReq->SetExpressCheckoutRequest = $setECReqType;
     $paypalService = new PayPal\Service\PayPalAPIInterfaceServiceService($config);
     try {
         /* wrap API method calls on the service object with a try catch */
         $setECResponse = $paypalService->SetExpressCheckout($setECReq);
     } catch (Exception $ex) {
         return Response::make(json_encode(array("error" => true, "message" => "Payment processing error")));
     }
     if (isset($setECResponse)) {
         if ($setECResponse->Ack == 'Success') {
             $token = $setECResponse->Token;
             // Redirect to paypal.com here
             $payPalURL = Config::get('project.paypal_api_url') . "webscr?cmd=_express-checkout&token={$token}&useraction=commit";
             // Store Data in session
             Session::put('_product', $product_id);
             Session::put('_plan', $plan_id);
             Session::put('_buyer', $buyer_id);
             return Response::make(json_encode(array("success" => true, "url" => $payPalURL)));
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Execute the setExpressCheckout process, forwards to paypal
  *
  * @param string $returnUrl
  * @param string $cancelUrl
  * @param array $subscriptionType
  * @param bool $recurring
  * @return string $token
  */
 public function createECResponse($returnUrl, $cancelUrl, array $subscriptionType, $recurring = false)
 {
     $token = null;
     $amount = $subscriptionType['amount'];
     $agreement = $subscriptionType['agreement'];
     $currency = Config::$a['commerce']['currency'];
     $setECReqDetails = new SetExpressCheckoutRequestDetailsType();
     $setECReqDetails->ReqConfirmShipping = 0;
     $setECReqDetails->NoShipping = 1;
     $setECReqDetails->AllowNote = 0;
     $setECReqDetails->ReturnURL = $returnUrl;
     $setECReqDetails->CancelURL = $cancelUrl;
     $setECReqDetails->SolutionType = 'Sole';
     if ($recurring) {
         // Create billing agreement for recurring payment
         $billingAgreementDetails = new BillingAgreementDetailsType('RecurringPayments');
         $billingAgreementDetails->BillingAgreementDescription = $agreement;
         $setECReqDetails->BillingAgreementDetails[0] = $billingAgreementDetails;
     }
     $paymentDetails = new PaymentDetailsType();
     $paymentDetails->PaymentAction = 'Sale';
     $paymentDetails->NotifyURL = Config::$a['paypal']['api']['ipn'];
     $paymentDetails->OrderTotal = new BasicAmountType($currency, $amount);
     $paymentDetails->ItemTotal = new BasicAmountType($currency, $amount);
     $paymentDetails->Recurring = 0;
     $itemDetails = new PaymentDetailsItemType();
     $itemDetails->Name = $subscriptionType['itemLabel'];
     $itemDetails->Amount = new BasicAmountType($currency, $amount);
     $itemDetails->Quantity = 1;
     // TODO this should be 'Digital' but Paypal requires you to change your account to a digital good account, which is a las
     $itemDetails->ItemCategory = 'Physical';
     $itemDetails->Number = $subscriptionType['id'];
     $paymentDetails->PaymentDetailsItem[0] = $itemDetails;
     $setECReqDetails->PaymentDetails[0] = $paymentDetails;
     // Paypal UI settings
     $setECReqDetails->BrandName = Config::$a['commerce']['receiver']['brandName'];
     // Execute checkout
     $setECReqType = new SetExpressCheckoutRequestType();
     $setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
     $setECReq = new SetExpressCheckoutReq();
     $setECReq->SetExpressCheckoutRequest = $setECReqType;
     $paypalService = new PayPalAPIInterfaceServiceService();
     $response = $paypalService->SetExpressCheckout($setECReq);
     if ($response->Ack == 'Success') {
         $token = $response->Token;
     } else {
         $log = Application::instance()->getLogger();
         $log->critical("Error getting checkout response: " . $response->Errors->ShortMessage);
     }
     return $token;
 }
 /**
  * Purchase Paypal
  * @param PaymentRequest $request
  * @param $productId
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 public function purchasePaypal(PaymentRequest $request, $productId)
 {
     $input = $request->all();
     list($product, $items, $total, $totalDollar) = $this->getPurchasedOptions($productId);
     if ($input['payment_method'] == 2) {
         $config = array('mode' => $this->modeApiPaypal, 'acct1.UserName' => $this->userApiPaypal, 'acct1.Password' => $this->passwordApiPaypal, 'acct1.Signature' => $this->signatureApiPaypal);
         // Create request details
         $setECReqDetails = new SetExpressCheckoutRequestDetailsType();
         // descripcion del item comprado
         $descriptionPayment = "";
         $total = 0;
         if ($product->option_id) {
             $option = Option::findOrFail($product->option_id);
             $descriptionPayment .= $option->name . ' ' . $option->price;
             $total += $option->price;
         }
         if ($product->tags->count()) {
             $descriptionPayment .= ' - Etiqueta: ' . $product->tags->first()->name . ' ' . $product->tags->first()->price;
             $total += $product->tags->first()->price;
         }
         $itemAmount = new BasicAmountType('USD', $totalDollar);
         $itemDetails = new PaymentDetailsItemType();
         $itemDetails->Name = $descriptionPayment;
         $itemDetails->Amount = $itemAmount;
         $itemDetails->Quantity = 1;
         $paymentDetails = new PaymentDetailsType();
         $paymentDetails->PaymentDetailsItem[0] = $itemDetails;
         $setECReqDetails->PaymentDetails[0] = $paymentDetails;
         $setECReqDetails->OrderTotal = $itemAmount;
         $setECReqDetails->OrderDescription = $descriptionPayment;
         //$setECReqDetails->PaymentAction = "Sale";
         //$setECReqDetails->cppheaderbackcolor = "#000000";
         $setECReqDetails->CancelURL = route('product_payment', $productId);
         $setECReqDetails->ReturnURL = route('paypal_receipt');
         $setECReqDetails->Custom = $productId;
         $setECReqType = new SetExpressCheckoutRequestType();
         $setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
         // Create request
         $setECReq = new SetExpressCheckoutReq();
         $setECReq->SetExpressCheckoutRequest = $setECReqType;
         // Perform request
         $paypalService = new PayPalAPIInterfaceServiceService($config);
         $setECResponse = $paypalService->SetExpressCheckout($setECReq);
         $tokenPaypal = $setECResponse->Token;
         // Check results
         if ($setECResponse->Ack == 'Success') {
         } else {
             flash('Respuesta Inválida');
             return redirect()->back();
         }
         Log::info('results of PAYPAL: ' . json_encode($setECResponse));
     }
     $paymentMethod = 2;
     return view('products.purchase')->with(compact('product', 'items', 'total', 'totalDollar', 'input', 'tokenPaypal', 'paymentMethod'));
 }