public function doEC()
 {
     $logger = new PPLoggingManager('DoExpressCheckout');
     // ## DoExpressCheckoutPaymentReq
     $doExpressCheckoutPaymentReq = new DoExpressCheckoutPaymentReq();
     $doExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
     // The timestamped token value that was returned in the
     // `SetExpressCheckout` response and passed in the
     // `GetExpressCheckoutDetails` request.
     $doExpressCheckoutPaymentRequestDetails->Token = "EC-2XW434901C650622T";
     // Unique paypal buyer account identification number as returned in
     // `GetExpressCheckoutDetails` Response
     $doExpressCheckoutPaymentRequestDetails->PayerID = "A9BVYX8XCR9ZQ";
     // ### Payment Information
     // list of information about the payment
     $paymentDetailsList = 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";
     // 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";
     // 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";
     // 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";
     $paymentDetailsList[0] = $paymentDetails1;
     $paymentDetailsList[1] = $paymentDetails2;
     $doExpressCheckoutPaymentRequestDetails->PaymentDetails = $paymentDetailsList;
     $doExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType($doExpressCheckoutPaymentRequestDetails);
     $doExpressCheckoutPaymentReq->DoExpressCheckoutPaymentRequest = $doExpressCheckoutPaymentRequest;
     // ## 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->DoExpressCheckoutPayment($doExpressCheckoutPaymentReq);
     } catch (Exception $ex) {
         $logger->error("Error Message : " + $ex->getMessage());
     }
     // ## Accessing response parameters
     // You can access the response parameters using getter methods in
     // response object as shown below
     // ### Success values
     if ($response->Ack == "Success") {
         // Transaction identification number of the transaction that was
         // created.
         // This field is only returned after a successful transaction
         // for DoExpressCheckout has occurred.
         if ($doExpressCheckoutPaymentResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo != null) {
             $paymentInfoArray = $doExpressCheckoutPaymentResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo;
             foreach ($paymentInfoArray as $payInfo) {
                 $logger->log("Transaction ID : " . $payInfo->TransactionID);
             }
         }
     } else {
         $logger->error("API Error Message : " . $response->Errors[0]->LongMessage);
     }
     return $response;
 }
$paymentDetails->OrderTotal = $orderTotal;
if (isset($_REQUEST['notifyURL'])) {
    $paymentDetails->NotifyURL = $_REQUEST['notifyURL'];
}
$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) {
    include_once "../Error.php";
    exit;
}
if (isset($DoECResponse)) {
    echo "<table>";
    echo "<tr><td>Ack :</td><td><div id='Ack'>{$DoECResponse->Ack}</div> </td></tr>";
    if (isset($DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo)) {
        echo "<tr><td>TransactionID :</td><td><div id='TransactionID'>" . $DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->TransactionID . "</div> </td></tr>";
    }
    echo "</table>";
    echo "<pre>";
    print_r($DoECResponse);
    echo "</pre>";
}
Example #3
0
 /**
  * DoExpressCheckout実行
  *
  */
 public function doExpressCheckout()
 {
     global $mts_simple_booking;
     // トークンと買い手IDをセット
     $this->token = urlencode($_GET['token']);
     $this->payerId = urlencode($_GET['PayerID']);
     $this->_add_sessData($this->sess_name, array('token' => $this->token, 'payerId' => $this->payerId));
     // bookingデータをセットする
     $mts_simple_booking->oBooking_form->setBooking($this->sess_data['booking']);
     // 計算書を取得する
     $bill = $mts_simple_booking->oBooking_form->make_bill();
     $currencyCode = $bill->currency_code;
     // PayPalアクセス準備
     //$this->_init_paypal_sdk('DoExpressCheckout');
     // 請求合計額を計算する
     $itemTotal = $bill->get_total();
     $taxTotal = $bill->tax_type == 2 ? $bill->get_amount_tax() : 0;
     //$orderTotal = new BasicAmountType($currencyCode, $itemTotal + $taxTotal);
     $orderTotal = new BasicAmountType();
     $orderTotal->currencyID = $currencyCode;
     $orderTotal->value = $itemTotal + $taxTotal;
     // 支払明細設定
     $paymentDetails = new PaymentDetailsType();
     $paymentDetails->OrderTotal = $orderTotal;
     // API設定
     $DoECRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
     $DoECRequestDetails->PayerID = $this->payerId;
     $DoECRequestDetails->Token = $this->token;
     $DoECRequestDetails->PaymentAction = 'Sale';
     $DoECRequestDetails->PaymentDetails[0] = $paymentDetails;
     $DoECRequest = new DoExpressCheckoutPaymentRequestType();
     $DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
     $DoECReq = new DoExpressCheckoutPaymentReq();
     $DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
     $paypalService = new PayPalAPIInterfaceServiceService();
     try {
         /* wrap API method calls on the service object with a try catch */
         $doECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
     } catch (Exception $ex) {
         // セッションデータに例外を追加保存する
         $this->_add_sessData($this->sess_name, array('doECException' => $ex));
         throw $ex;
     }
     // セッションデータにDoExpressCheckoutの実行結果を追加する
     $this->_add_sessData($this->sess_name, array('doECResponse' => serialize($doECResponse)));
     if ($doECResponse->Ack == 'Success') {
         return true;
     }
     return false;
 }
 /**
  * @param $token
  * @param $paypalUserId
  * @param $amount
  * @param $currency
  * @return DoExpressCheckoutPaymentResponseType
  */
 public function doExpressCheckout($token, $paypalUserId, $amount, $currency)
 {
     $logger = new PPLoggingManager('GetTransactionDetails');
     /*
      *  Unique PayPal buyer account identification number as returned in the GetExpressCheckoutDetails response
      */
     $payerId = urlencode($paypalUserId);
     $paymentAction = urlencode("Sale");
     $paypalService = new PayPalAPIInterfaceServiceService();
     /*
      * 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 = $currency;
     $orderTotal->value = $amount;
     $paymentDetails = new PaymentDetailsType();
     $paymentDetails->OrderTotal = $orderTotal;
     //		$paymentDetails->NotifyURL = $_REQUEST['notifyURL'];
     $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) {
         return FALSE;
         //todo error stuff
     }
     if ($DoECResponse->Ack == 'Success') {
         return $DoECResponse;
     } else {
         $logger->error("API Error Message : " . $DoECResponse);
         return FALSE;
     }
 }
 public function doCheckout($payerId)
 {
     if (empty($this->ipnUrl)) {
         Yii::error('Ipn url haven\'t initialized');
         throw new Exception('Ipn url haven\'t initialized');
     }
     $settings = PaypalSettings::find()->one();
     $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);
     $orderTotal = new \BasicAmountType();
     $orderTotal->currencyID = $this->currency;
     $orderTotal->value = $this->payment_price;
     $paymentDetails = new \PaymentDetailsType();
     $paymentDetails->PaymentAction = 'Sale';
     $paymentDetails->NotifyURL = $this->ipnUrl;
     $paymentDetails->OrderTotal = $orderTotal;
     $DoECRequestDetails = new \DoExpressCheckoutPaymentRequestDetailsType();
     $DoECRequestDetails->PayerID = $payerId;
     $DoECRequestDetails->Token = $this->payment_token;
     $DoECRequestDetails->PaymentDetails[0] = $paymentDetails;
     $DoECRequest = new \DoExpressCheckoutPaymentRequestType();
     $DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
     $DoECRequest->Version = $this->ECVersion;
     $DoECReq = new \DoExpressCheckoutPaymentReq();
     $DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
     $DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
     if (!empty($DoECResponse->Errors)) {
         $this->errors = var_export($DoECResponse->Errors, true);
         $this->status = self::STATUS_ERROR;
         $this->save();
         Yii::error('Errors: ' . var_export($DoECResponse->Errors, true));
         return false;
     }
     $status = strtoupper($DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->PaymentStatus);
     $this->status = $status;
     $this->save();
     return true;
 }
 public function confirm($id, $token, $payer_id)
 {
     $products = $this->products;
     $product = $products[$id];
     if (empty($product)) {
         return;
     }
     $paypal_service = new PayPalAPIInterfaceServiceService($this->pp_settings);
     $ec_details_req_type = new GetExpressCheckoutDetailsRequestType($token);
     $ec_detail_req = new GetExpressCheckoutDetailsReq();
     $ec_detail_req->GetExpressCheckoutDetailsRequest = $ec_details_req_type;
     $ec_resp = $paypal_service->GetExpressCheckoutDetails($ec_detail_req);
     if (!$ec_resp && $ec_resp->Ack != 'Success') {
         throw new Exception("Paypal Request Failed");
     }
     //we now have the payer info
     $payer_info = $ec_resp->GetExpressCheckoutDetailsResponseDetails->PayerInfo;
     if ($product['recurring']) {
         $order_total = new BasicAmountType($product['currency'], $product['init_amount']);
     } else {
         $order_total = new BasicAmountType($product['currency'], $product['amount']);
     }
     $payment_details = new PaymentDetailsType();
     $payment_details->OrderTotal = $order_total;
     $payment_details->NotifyURL = $this->thankyou_url . '?action=ipn&id=' . $id;
     $do_ec_details = new DoExpressCheckoutPaymentRequestDetailsType();
     $do_ec_details->PayerID = $payer_id;
     $do_ec_details->Token = $token;
     $do_ec_details->PaymentDetails[0] = $payment_details;
     $do_ec_request = new DoExpressCheckoutPaymentRequestType();
     $do_ec_request->DoExpressCheckoutPaymentRequestDetails = $do_ec_details;
     if ($order_total->value > 0) {
         $do_ec = new DoExpressCheckoutPaymentReq();
         $do_ec->DoExpressCheckoutPaymentRequest = $do_ec_request;
         $do_ec_resp = $paypal_service->DoExpressCheckoutPayment($do_ec);
         if (!$do_ec_resp || $do_ec_resp->Ack != 'Success') {
             throw new Exception("Paypal Checkout Error Has Occured");
         }
         //we now have a payment info. Yeehaaa
         $payment_info = current($do_ec_resp->DoExpressCheckoutPaymentResponseDetails->PaymentInfo);
         $accept_statuses = array('Completed', 'In-Progress', 'Pending', 'Processed');
         if (!in_array($payment_info->PaymentStatus, $accept_statuses)) {
             throw new Exception("Paypal Payment Checkout Failed");
         }
     }
     if ($product['recurring']) {
         //create a recurring payment profile
         $schedule_details = new ScheduleDetailsType();
         $payment_billing_period = new BillingPeriodDetailsType();
         $payment_billing_period->BillingFrequency = $product['recur_billing_frequency'];
         $payment_billing_period->BillingPeriod = $product['recur_billing_period'];
         $payment_billing_period->Amount = new BasicAmountType($product['currency'], $product['recur_amount']);
         $schedule_details->PaymentPeriod = $payment_billing_period;
         $schedule_details->Description = sprintf("%s %s", $product['name'], __("Subscription", "wishlist-member"));
         $recur_profile_details = new RecurringPaymentsProfileDetailsType();
         $recur_profile_details->BillingStartDate = date(DATE_ATOM, strtotime(sprintf("+%s %s", $product['recur_billing_frequency'], $product['recur_billing_period'])));
         $create_recur_paypay_profile_details = new CreateRecurringPaymentsProfileRequestDetailsType();
         $create_recur_paypay_profile_details->Token = $token;
         $create_recur_paypay_profile_details->ScheduleDetails = $schedule_details;
         $create_recur_paypay_profile_details->RecurringPaymentsProfileDetails = $recur_profile_details;
         $create_recur_profile = new CreateRecurringPaymentsProfileRequestType();
         $create_recur_profile->CreateRecurringPaymentsProfileRequestDetails = $create_recur_paypay_profile_details;
         $create_recur_profile_req = new CreateRecurringPaymentsProfileReq();
         $create_recur_profile_req->CreateRecurringPaymentsProfileRequest = $create_recur_profile;
         $create_profile_resp = $paypal_service->CreateRecurringPaymentsProfile($create_recur_profile_req);
         if (!$create_profile_resp || $create_profile_resp->Ack != 'Success') {
             throw new Exception("Could not create recurring profile");
         }
     }
     $address = array();
     $address['company'] = $payer_info->PayerBusiness;
     $address['address1'] = $payer_info->Address->Street1;
     $address['address2'] = $payer_info->Address->Street2;
     $address['city'] = $payer_info->Address->CityName;
     $address['state'] = $payer_info->Address->StateOrProvince;
     $address['zip'] = $payer_info->Address->PostalCode;
     $address['country'] = $payer_info->Address->CountryName;
     $_POST['wpm_useraddress'] = $address;
     $_POST['lastname'] = $payer_info->PayerName->LastName;
     $_POST['firstname'] = $payer_info->PayerName->FirstName;
     $_POST['action'] = 'wpm_register';
     $_POST['wpm_id'] = $product['sku'];
     $_POST['username'] = $payer_info->Payer;
     $_POST['email'] = $payer_info->Payer;
     $_POST['password1'] = $_POST['password2'] = $this->wlm->PassGen();
     $_POST['sctxnid'] = $product['recurring'] ? $create_profile_resp->CreateRecurringPaymentsProfileResponseDetails->ProfileID : $payment_info->TransactionID;
     $pending_statuses = array('In-Progress', 'Pending');
     if (in_array($payment_info->PaymentStatus, $pending_statuses) || $create_profile_resp->CreateRecurringPaymentsProfileResponseDetails->ProfileStatus == 'PendingProfile') {
         $this->wlm->ShoppingCartRegistration(null, null, 'Paypal Pending');
     } else {
         $this->wlm->ShoppingCartRegistration();
     }
 }