Пример #1
0
 /**
  * SetExpressCheckout実行
  *
  */
 public function setExpressCheckout()
 {
     global $mts_simple_booking;
     // 予約データと計算書データを取得する
     $booking = $mts_simple_booking->oBooking_form->getBooking();
     $bill = $mts_simple_booking->oBooking_form->make_bill();
     // PayPalアクセス準備
     //$this->_init_paypal_sdk('SetExpressCheckout');
     // Nonceデータを含める
     $this->sess_data = array('page_url' => $this->page_url, 'nonce' => $this->_get_nonce(), 'booking' => $booking);
     // 予約データをセッションテーブルに保存
     $this->sess_name = $this->_save_sessData($this->sess_data);
     // リターンURLを求める
     $params = array('sid' => $this->sess_name, 'nonce' => $this->sess_data['nonce'], 'page_url' => $this->page_url);
     $returnUrl = add_query_arg(array('pp' => 'checkout') + $params, $this->return_url);
     $cancelUrl = add_query_arg(array('pp' => 'cancel') + $params, $this->return_url);
     // Checkout 明細オブジェクト
     $paymentDetails = new PaymentDetailsType();
     $paymentDetails->PaymentAction = 'Sale';
     $currencyCode = $bill->currency_code;
     // 予約品目の料金明細設定
     foreach ($this->type as $type) {
         //($i=0; $i<count($_REQUEST['itemAmount']); $i++) {
         // 人数または料金が0の場合は明細に掲載しない
         if ($bill->number->{$type} == 0 || $bill->amount->{$type} == 0) {
             continue;
         }
         // 明細データ
         $itemDetails = new PaymentDetailsItemType();
         $itemDetails->Name = $bill->article_name . ' ' . apply_filters('booking_form_bill_label', __(ucwords($type), $this->domain));
         $itemDetails->Amount = new BasicAmountType($currencyCode, $bill->amount->{$type});
         $itemDetails->Quantity = $bill->number->{$type};
         $itemDetails->ItemCategory = 'Physical';
         $paymentDetails->PaymentDetailsItem[] = $itemDetails;
     }
     // オプションの料金明細設定
     $option_items = $bill->option_items;
     if (!empty($option_items)) {
         foreach ($option_items as $option_item) {
             $itemDetails = new PaymentDetailsItemType();
             $itemDetails->Name = $option_item['name'];
             $itemDetails->Amount = $option_item['price'];
             $itemDetails->Quantity = $option_item['number'];
             $itemDetails->ItemCategory = 'Physical';
             $paymentDetails->PaymentDetailsItem[] = $itemDetails;
         }
     }
     //$paymentDetails->ShipToAddress = $address;
     $itemTotal = $bill->get_total();
     $taxTotal = $bill->tax_type == 2 ? $bill->get_amount_tax() : 0;
     $paymentDetails->ItemTotal = new BasicAmountType($currencyCode, $itemTotal);
     $paymentDetails->TaxTotal = new BasicAmountType($currencyCode, $taxTotal);
     $paymentDetails->OrderTotal = new BasicAmountType($currencyCode, $itemTotal + $taxTotal);
     //$paymentDetails->HandlingTotal = new BasicAmountType($currencyCode, $bill->total_cost);
     //$paymentDetails->insuranceTotal = new BasicAmountType($currencyCode, $_REQUEST['insuranceTotal']);
     //$paymentDetails->ShippingTotal = new BasicAmountType($currencyCode, $itemTotal);
     // APIデータ設定
     $setECReqDetails = new SetExpressCheckoutRequestDetailsType();
     $setECReqDetails->PaymentDetails[0] = $paymentDetails;
     $setECReqDetails->CancelURL = $cancelUrl;
     $setECReqDetails->ReturnURL = $returnUrl;
     $setECReqDetails->cppheaderimage = $this->logo_url;
     $setECReqDetails->BrandName = $bill->shop_name;
     $setECReqDetails->LocaleCode = 'ja_JP';
     $setECReqDetails->SolutionType = 'Sole';
     $setECReqDeatils->LandingPage = 'Billing';
     $setECReqDetails->BuyerEmail = $booking['client']['email'];
     $setECReqType = new SetExpressCheckoutRequestType();
     $setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
     $setECReq = new SetExpressCheckoutReq();
     $setECReq->SetExpressCheckoutRequest = $setECReqType;
     // セッションデータにリクエストを追加する
     $this->_add_sessData($this->sess_name, array('setECReq' => serialize($setECReq)));
     $paypalService = new PayPalAPIInterfaceServiceService();
     try {
         /* wrap API method calls on the service object with a try catch */
         $setECResponse = $paypalService->SetExpressCheckout($setECReq);
     } catch (Exception $ex) {
         throw $ex;
     }
     // API SetExpressCheckoutの結果を保存する
     $token = '';
     if (isset($setECResponse)) {
         // セッションデータに接続結果を追加する
         $this->_add_sessData($this->sess_name, array('setECResponse' => serialize($setECResponse)));
         // PayPal支払処理へリダイレクトする
         if ($setECResponse->Ack == 'Success') {
             // PayPalへのリダイレクト
             $paypalUrl = PPConfigManager::getInstance()->get('service.RedirectURL') . '_express-checkout&useraction=commit&token=' . $setECResponse->Token;
             //echo "<a href=$paypalUrl><b>Redirect to PayPal to login</b></a><br />";
             //exit();
             header("Location: {$paypalUrl}");
             exit;
         }
     }
     return $setECResponse;
 }
Пример #2
0
$PaymentDetails->PaymentAction = 'Sale';
$PaymentDetails->ItemTotal = $orderTotal;
$PaymentDetails->TaxTotal = $taxTotal;
$setECReqDetails = new SetExpressCheckoutRequestDetailsType();
$setECReqDetails->PaymentDetails[0] = $PaymentDetails;
$setECReqDetails->CancelURL = $cancelUrl;
$setECReqDetails->ReturnURL = $returnUrl;
$setECReqDetails->ReqConfirmShipping = 0;
$setECReqDetails->NoShipping = 1;
$setECReqType = new SetExpressCheckoutRequestType();
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReqType->Version = '92.0';
$setECReq = new SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
// storing in session to use in DoExpressCheckout
$_SESSION['amount'] = $_REQUEST['amount'];
$_SESSION['currencyID'] = $_REQUEST['currencyId'];
$PayPal_service = new PayPalAPIInterfaceServiceService();
$setECResponse = $PayPal_service->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 {
    echo "error in SetEC API call";
}
$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 = $_REQUEST['allowNote'];
$setECReqType = new SetExpressCheckoutRequestType();
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReq = new SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
$paypalService = new PayPalAPIInterfaceServiceService();
try {
    /* wrap API method calls on the service object with a try catch */
    $setECResponse = $paypalService->SetExpressCheckout($setECReq);
} catch (Exception $ex) {
    include_once "../Error.php";
    exit;
}
if (isset($setECResponse)) {
    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>';
    if ($setECResponse->Ack == 'Success') {
        $token = $setECResponse->Token;
        // Redirect to paypal.com here
Пример #4
0
 public function setExpressCheckout($amount, $currency, $presenter_site_url)
 {
     $logger = new PPLoggingManager('GetTransactionDetails');
     /*
      * Digital goods payments combine JavaScript with the Express Checkout API
      * to streamline the checkout process for buyers of digital goods.
      * 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
      *
      */
     $serverName = $_SERVER['SERVER_NAME'];
     $serverPort = $_SERVER['SERVER_PORT'];
     $url = dirname('http://' . $serverName . ':' . $serverPort . $_SERVER['REQUEST_URI']);
     /*
      * 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.
      */
     $returnUrl = "http://" . $serverName . DIRECTORY_SEPARATOR . $presenter_site_url . "/products/paypalconfirm";
     /*
      * 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
      */
     $cancelUrl = "http://" . $serverName . DIRECTORY_SEPARATOR . $presenter_site_url . "/products/checkout";
     /*
      * Total cost of the transaction to the buyer. If shipping cost 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 = $currency;
     $orderTotal->value = $amount;
     $taxTotal = new BasicAmountType();
     $taxTotal->currencyID = $currency;
     $taxTotal->value = '0.0';
     $itemDetails = new PaymentDetailsItemType();
     $itemDetails->Name = 'Website order';
     $itemDetails->Amount = $orderTotal;
     /*
      * Item quantity. This field is required when you pass a value for
      * ItemCategory. For digital goods (ItemCategory=Digital), this field is required.
      */
     $itemDetails->Quantity = '1';
     /*
      * Indicates whether an item is digital or physical. For digital goods,
      * this field is required and must be set to Digital
      */
     $itemDetails->ItemCategory = 'Physical';
     $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';
     /*
      * 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->PaymentDetails[0] = $PaymentDetails;
     $setECReqDetails->CancelURL = $cancelUrl;
     $setECReqDetails->ReturnURL = $returnUrl;
     /*
     		 * 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 = 0;
     /*
     		 * 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 = 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();
     $setECResponse = $paypalService->SetExpressCheckout($setECReq);
     if ($setECResponse->Ack == 'Success') {
         $token = $setECResponse->Token;
         return $token;
     } else {
         $logger->error("API Error Message : " . $setECResponse);
         return FALSE;
     }
 }
 public function setEC()
 {
     $logger = new PPLoggingManager('SetExpressCheckout');
     // ## SetExpressCheckoutReq
     $setExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
     // 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.
     // `Note:
     // PayPal recommends that the value be the final review page on which
     // the buyer confirms the order and payment or billing agreement.`
     $setExpressCheckoutRequestDetails->ReturnURL = "http://localhost/return";
     // 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.
     // `Note:
     // PayPal recommends that the value be the original page on which the
     // buyer chose to pay with PayPal or establish a billing agreement.`
     $setExpressCheckoutRequestDetails->CancelURL = "http://localhost/cancel";
     // ### Payment Information
     // list of information about the payment
     $paymentDetailsArray = array();
     // information about the first payment
     $paymentDetails1 = new PaymentDetailsType();
     // Total cost of the transaction to the buyer. If shipping cost 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.
     //
     // * `Currency Code` - You must set the currencyID attribute to one of the
     // 3-character currency codes for any of the supported PayPal
     // currencies.
     // * `Amount`
     $orderTotal1 = new BasicAmountType("USD", "2.00");
     $paymentDetails1->OrderTotal = $orderTotal1;
     // 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.
     // `Note:
     // You cannot set this field to Sale in SetExpressCheckout request and
     // then change the value to Authorization or Order in the
     // DoExpressCheckoutPayment request. If you set the field to
     // Authorization or Order in SetExpressCheckout, you may set the field
     // to Sale.`
     $paymentDetails1->PaymentAction = "Order";
     // Unique identifier for the merchant. For parallel payments, this field
     // is required and must contain the Payer Id or the email address of the
     // merchant.
     $sellerDetails1 = new SellerDetailsType();
     $sellerDetails1->PayPalAccountID = "*****@*****.**";
     $paymentDetails1->SellerDetails = $sellerDetails1;
     // A unique identifier of the specific payment request, which is
     // required for parallel payments.
     $paymentDetails1->PaymentRequestID = "PaymentRequest1";
     // `Address` to which the order is shipped, which takes mandatory params:
     //
     // * `Street Name`
     // * `City`
     // * `State`
     // * `Country`
     // * `Postal Code`
     $shipToAddress1 = new AddressType();
     $shipToAddress1->Street1 = "Ape Way";
     $shipToAddress1->CityName = "Austin";
     $shipToAddress1->StateOrProvince = "TX";
     $shipToAddress1->Country = "US";
     $shipToAddress1->PostalCode = "78750";
     // 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.
     $paymentDetails1->NotifyURL = "http://localhost/ipn";
     $paymentDetails1->ShipToAddress = $shipToAddress1;
     // information about the second payment
     $paymentDetails2 = new PaymentDetailsType();
     // Total cost of the transaction to the buyer. If shipping cost 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.
     //
     // * `Currency Code` - You must set the currencyID attribute to one of the
     // 3-character currency codes for any of the supported PayPal
     // currencies.
     // * `Amount`
     $orderTotal2 = new BasicAmountType("USD", "4.00");
     $paymentDetails2->OrderTotal = $orderTotal2;
     // 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.
     // `Note:
     // You cannot set this field to Sale in SetExpressCheckout request and
     // then change the value to Authorization or Order in the
     // DoExpressCheckoutPayment request. If you set the field to
     // Authorization or Order in SetExpressCheckout, you may set the field
     // to Sale.`
     $paymentDetails2->PaymentAction = "Order";
     // Unique identifier for the merchant. For parallel payments, this field
     // is required and must contain the Payer Id or the email address of the
     // merchant.
     $sellerDetails2 = new SellerDetailsType();
     $sellerDetails2->PayPalAccountID = "*****@*****.**";
     $paymentDetails2->SellerDetails = $sellerDetails2;
     // A unique identifier of the specific payment request, which is
     // required for parallel payments.
     $paymentDetails2->PaymentRequestID = "PaymentRequest2";
     // `Address` to which the order is shipped, which takes mandatory params:
     //
     // * `Street Name`
     // * `City`
     // * `State`
     // * `Country`
     // * `Postal Code`
     $shipToAddress2 = new AddressType();
     $shipToAddress2->Street1 = "Ape Way";
     $shipToAddress2->CityName = "Austin";
     $shipToAddress2->StateOrProvince = "TX";
     $shipToAddress2->Country = "US";
     $shipToAddress2->PostalCode = "78750";
     // 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.
     $paymentDetails2->NotifyURL = "http://localhost/ipn";
     $paymentDetails2->ShipToAddress = $shipToAddress2;
     $paymentDetailsArray[0] = $paymentDetails1;
     $paymentDetailsArray[1] = $paymentDetails2;
     $setExpressCheckoutRequestDetails->PaymentDetails = $paymentDetailsArray;
     $setExpressCheckoutReq = new SetExpressCheckoutReq();
     $setExpressCheckoutRequest = new SetExpressCheckoutRequestType($setExpressCheckoutRequestDetails);
     $setExpressCheckoutReq->SetExpressCheckoutRequest = $setExpressCheckoutRequest;
     // ## 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->SetExpressCheckout($setExpressCheckoutReq);
     } 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") {
         // ### Redirecting to PayPal for authorization
         // Once you get the "Success" response, needs to authorise the
         // transaction by making buyer to login into PayPal. For that,
         // need to construct redirect url using EC token from response.
         // For example,
         // `redirectURL="https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=". $response->Token();`
         // Express Checkout Token
         $logger->log("EC Token:" . $response->Token);
     } else {
         $logger->error("API Error Message : " . $response->Errors[0]->LongMessage);
     }
     return $response;
 }
 /**
  * generates paypal transaction. saves it payment to base
  * @return string URL
  * @throws Exception
  */
 public function createExpressPayment($amount, $quantity, $name = 'Goods')
 {
     /*
      * INITIAL CHECKS
      */
     if (!is_int($quantity) || $quantity <= 0) {
         Yii::error('Quantity must be integer > 0');
         throw new Exception('Quantity must be integer > 0');
     }
     if (!is_numeric($amount) || $amount <= 0) {
         Yii::error('Amount must be number > 0');
         throw new Exception('Amount must be number > 0');
     }
     if (empty($this->expressSuccessUrl) || empty($this->cancelUrl) || empty($this->currency)) {
         Yii::error('Success url or cancel url or currency haven\'t initialized');
         throw new Exception('Success url or cancel url or currency haven\'t initialized');
     }
     /*
      * LOGIC
      */
     $settings = PaypalSettings::find()->one();
     if (empty($settings)) {
         Yii::error('Settings of PayPal haven\'t initialized');
         throw new Exception('Settings of PayPal haven\'t initialized');
     }
     $config = ['mode' => $settings->mode ? 'live' : 'sandbox', 'acct1.UserName' => $settings->api_username, 'acct1.Password' => $settings->api_password, 'acct1.Signature' => $settings->api_signature];
     $paypalService = new \PayPalAPIInterfaceServiceService($config);
     $paymentDetails = new \PaymentDetailsType();
     $itemDetails = new \PaymentDetailsItemType();
     $itemDetails->Name = $name;
     $itemDetails->Amount = $amount;
     $itemDetails->Quantity = $quantity;
     $paymentDetails->PaymentDetailsItem[0] = $itemDetails;
     $orderTotal = new \BasicAmountType();
     $orderTotal->currencyID = $this->currency;
     $orderTotal->value = $amount * $quantity;
     $paymentDetails->PaymentAction = 'Sale';
     $setECReqDetails = new \SetExpressCheckoutRequestDetailsType();
     $setECReqDetails->PaymentDetails[0] = $paymentDetails;
     $setECReqDetails->CancelURL = $this->cancelUrl;
     $setECReqDetails->ReturnURL = $this->expressSuccessUrl;
     $setECReqDetails->OrderTotal = $orderTotal;
     $setECReqType = new \SetExpressCheckoutRequestType();
     $setECReqType->Version = $this->ECVersion;
     $setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
     $setECReq = new \SetExpressCheckoutReq();
     $setECReq->SetExpressCheckoutRequest = $setECReqType;
     $setECResponse = $paypalService->SetExpressCheckout($setECReq);
     if (is_null($setECResponse->Errors)) {
         Yii::info('Payment created succesfully. Token is "' . $setECResponse->Token . '"');
         $this->token = $setECResponse->Token;
         $this->setAttributes(['payment_price' => $amount, 'payment_token' => $this->token, 'currency' => $this->currency, 'status' => self::STATUS_CREATED_BY_SITE]);
         $this->save();
         return $this;
     } else {
         Yii::error('Errors: ' . var_export($setECResponse->Errors, true));
         throw new Exception('Errors: ' . var_export($setECResponse->Errors, true));
     }
 }
 public function purchase_express($id)
 {
     $products = $this->products;
     $product = $products[$id];
     if (empty($product)) {
         return;
     }
     $paypal_service = new PayPalAPIInterfaceServiceService($this->pp_settings);
     $payment_details = new PaymentDetailsType();
     if ($product['recurring']) {
         $item_details = new PaymentDetailsItemType();
         $item_details->Name = $product['name'];
         $item_details->Amount = $product['init_amount'];
         $item_details->Quantity = 1;
         $payment_details->OrderTotal = new BasicAmountType($product['currency'], $product['init_amount']);
         $billing_agreement = new BillingAgreementDetailsType('RecurringPayments');
         $billing_agreement->BillingAgreementDescription = sprintf("%s %s", $product['name'], __("Subscription", "wishlist-member"));
     } else {
         $item_details = new PaymentDetailsItemType();
         $item_details->Name = $product['name'];
         $item_details->Amount = $product['amount'];
         $item_details->Quantity = 1;
         $payment_details->OrderTotal = new BasicAmountType($product['currency'], $product['amount']);
     }
     $payment_details->PaymentDetailsItem[$i] = $item_details;
     $ec_req_details = new SetExpressCheckoutRequestDetailsType();
     $ec_req_details->NoShipping = 0;
     $ec_req_details->ReqConfirmShipping = 0;
     $ec_req_details->SolutionType = 'Sole';
     $ec_req_details->ReturnURL = $this->thankyou_url . '?action=confirm&id=' . $id;
     $ec_req_details->CancelURL = $this->thankyou_url . '?action=confirm&id=' . $id;
     $ec_req_details->LandingPage = 'Billing';
     $ec_req_details->PaymentDetails[0] = $payment_details;
     if (isset($billing_agreement)) {
         $ec_req_details->BillingAgreementDetails = array($billing_agreement);
     }
     $ec_req_type = new SetExpressCheckoutRequestType();
     $ec_req_type->SetExpressCheckoutRequestDetails = $ec_req_details;
     $ec_req = new SetExpressCheckoutReq();
     $ec_req->SetExpressCheckoutRequest = $ec_req_type;
     $ec_res = $paypal_service->SetExpressCheckout($ec_req);
     if ($ec_res && $ec_res->Ack == 'Success') {
         $next_loc = sprintf("%s/webscr?cmd=_express-checkout&token=%s", $this->pp_settings['gateway'], $ec_res->Token);
         wp_redirect($next_loc);
         die;
     } else {
         //var_dump($ec_res);
     }
 }