public function createRecurringProfile()
 {
     $logger = new PPLoggingManager('CreateRecurringPaymentProfile');
     // ## CreateRecurringPaymentsProfileReq
     $createRPProfileReq = new CreateRecurringPaymentsProfileReq();
     $createRPProfileRequestType = new CreateRecurringPaymentsProfileRequestType();
     // 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("2013-12-31T13:01:19+00:00");
     // Billing amount for each billing cycle during this payment period.
     // This amount does not include shipping and tax amounts.
     // `Note:
     // All amounts in the CreateRecurringPaymentsProfile request must have
     // the same currency.`
     $billingAmount = new BasicAmountType("USD", "3.00");
     // 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`
     $paymentPeriod = new BillingPeriodDetailsType("Day", "5", $billingAmount);
     // 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("description", $paymentPeriod);
     // `CreateRecurringPaymentsProfileRequestDetailsType` which takes
     // mandatory params:
     //
     // * `Recurring Payments Profile Details`
     // * `Schedule Details`
     $createRecurringPaymentsProfileRequestDetails = new CreateRecurringPaymentsProfileRequestDetailsType($RPProfileDetails, $scheduleDetails);
     // Either EC token or a credit card number is required.If you include
     // both token and credit card number, the token is used and credit card number is
     // ignored
     // In case of setting EC token,
     // `createRecurringPaymentsProfileRequestDetails.setToken("EC-5KH01765D1724703R");`
     // A timestamped token, the value of which was returned in the response
     // to the first call to SetExpressCheckout. Call
     // CreateRecurringPaymentsProfile once for each billing
     // agreement included in SetExpressCheckout request and use the same
     // token for each call. Each CreateRecurringPaymentsProfile request
     // creates a single recurring payments profile.
     // `Note:
     // Tokens expire after approximately 3 hours.`
     // Credit card information for recurring payments using direct payments.
     $creditCard = new CreditCardDetailsType();
     // Type of credit card. For UK, only Maestro, MasterCard, Discover, and
     // Visa are allowable. For Canada, only MasterCard and Visa are
     // allowable and Interac debit cards are not supported. It is one of the
     // following values:
     //
     // * Visa
     // * MasterCard
     // * Discover
     // * Amex
     // * Solo
     // * Switch
     // * Maestro: See note.
     // `Note:
     // If the credit card type is Maestro, you must set currencyId to GBP.
     // In addition, you must specify either StartMonth and StartYear or
     // IssueNumber.`
     $creditCard->CreditCardType = "Visa";
     // Credit Card Number
     $creditCard->CreditCardNumber = "4442662639546634";
     // Credit Card Expiration Month
     $creditCard->ExpMonth = "12";
     // Credit Card Expiration Year
     $creditCard->ExpYear = "2016";
     $createRecurringPaymentsProfileRequestDetails->CreditCard = $creditCard;
     $createRPProfileRequestType->CreateRecurringPaymentsProfileRequestDetails = $createRecurringPaymentsProfileRequestDetails;
     $createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequestType;
     // ## 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->CreateRecurringPaymentsProfile($createRPProfileReq);
     } 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") {
         // A unique identifier for future reference to the details of
         // this recurring payment.
         $logger->log("Profile ID: " . $response->CreateRecurringPaymentsProfileResponseDetails->ProfileID);
     } else {
         $logger->error("API Error Message : " . $response->Errors[0]->LongMessage);
     }
     return $response;
 }
$paymentBillingPeriod->BillingPeriod = $_REQUEST['billingPeriod'];
$paymentBillingPeriod->Amount = $trialAmount;
$paymentBillingPeriod->TotalBillingCycles = $_REQUEST['totalBillingCycles'];
$trialBillingPeriod = new BillingPeriodDetailsType();
$trialBillingPeriod->BillingFrequency = $_REQUEST['trialBillingFrequency'];
$trialBillingPeriod->BillingPeriod = $_REQUEST['trialBillingPeriod'];
$trialBillingPeriod->Amount = $trialAmount;
$trialBillingPeriod->TotalBillingCycles = $_REQUEST['trialBillingCycles'];
$scheduleDetails = new ScheduleDetailsType();
$scheduleDetails->Description = $_REQUEST['profileDescription'];
$scheduleDetails->ActivationDetails = $activationDetails;
$scheduleDetails->TrialPeriod = $trialBillingPeriod;
$scheduleDetails->PaymentPeriod = $paymentBillingPeriod;
$scheduleDetails->MaxFailedPayments = $_REQUEST['maxFailedPayments'];
$scheduleDetails->AutoBillOutstandingAmount = $_REQUEST['autoBillOutstandingAmount'];
$createRPProfileRequestDetail = new CreateRecurringPaymentsProfileRequestDetailsType();
$createRPProfileRequestDetail->CreditCard = $creditCard;
//$createRPProfileRequestDetail->Token  = $_REQUEST['token'];
$createRPProfileRequestDetail->ScheduleDetails = $scheduleDetails;
$createRPProfileRequestDetail->RecurringPaymentsProfileDetails = $RPProfileDetails;
$createRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
$createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetail;
$createRPProfileRequest->Version = 92;
$createRPProfileReq = new CreateRecurringPaymentsProfileReq();
$createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;
$paypalService = new PayPalAPIInterfaceServiceService();
$createRPProfileResponse = $paypalService->CreateRecurringPaymentsProfile($createRPProfileReq);
echo "<pre>";
print_r($createRPProfileResponse);
echo "</pre>";
require_once '../Response.php';
Esempio n. 3
0
 function subscribe($sTocken)
 {
     $this->checkTrialAllowed(array('type' => 'token', 'value' => $sTocken));
     $oRPProfileDetails = new RecurringPaymentsProfileDetailsType();
     $oRPProfileDetails->BillingStartDate = date(DATE_ATOM);
     $oPaymentBillingPeriod = new BillingPeriodDetailsType();
     $oPaymentBillingPeriod->BillingPeriod = $this->sPeriodRegular;
     $oPaymentBillingPeriod->BillingFrequency = $this->iFrequencyRegular;
     $oPaymentBillingPeriod->TotalBillingCycles = $this->iBillingCyclesRegular;
     $oPaymentBillingPeriod->Amount = new BasicAmountType($this->sCurrencyCode, $this->fAmountRegular);
     $oScheduleDetails = new ScheduleDetailsType();
     $oScheduleDetails->Description = $this->sDescription;
     switch ($this->sActivationType) {
         case BX_SITES_PP_ACTIVATION_INIT_AMOUNT:
             $oActivationDetails = new ActivationDetailsType();
             $oActivationDetails->InitialAmount = new BasicAmountType($this->sCurrencyCode, $this->fAmountTrial);
             $oActivationDetails->FailedInitialAmountAction = 'CancelOnFailure';
             $oScheduleDetails->ActivationDetails = $oActivationDetails;
             break;
         case BX_SITES_PP_ACTIVATION_TRIAL_PERIOD:
             if (!$this->bTrial) {
                 break;
             }
             $oTrialBillingPeriod = new BillingPeriodDetailsType();
             $oTrialBillingPeriod->BillingPeriod = $this->sPeriodTrial;
             $oTrialBillingPeriod->BillingFrequency = $this->iFrequencyTrial;
             $oTrialBillingPeriod->TotalBillingCycles = $this->iBillingCyclesTrial;
             $oTrialBillingPeriod->Amount = new BasicAmountType($this->sCurrencyCode, $this->fAmountTrial);
             $oScheduleDetails->TrialPeriod = $oTrialBillingPeriod;
             break;
     }
     $oScheduleDetails->PaymentPeriod = $oPaymentBillingPeriod;
     $oScheduleDetails->MaxFailedPayments = 1;
     $oScheduleDetails->AutoBillOutstandingAmount = 'NoAutoBill';
     // 'AddToNextBilling'
     $oRPProfileRequestDetail = new CreateRecurringPaymentsProfileRequestDetailsType();
     $oRPProfileRequestDetail->Token = $sTocken;
     $oRPProfileRequestDetail->ScheduleDetails = $oScheduleDetails;
     $oRPProfileRequestDetail->RecurringPaymentsProfileDetails = $oRPProfileDetails;
     $oRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
     $oRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $oRPProfileRequestDetail;
     $oRPProfileReq = new CreateRecurringPaymentsProfileReq();
     $oRPProfileReq->CreateRecurringPaymentsProfileRequest = $oRPProfileRequest;
     $oPaypalService = new PayPalAPIInterfaceServiceService();
     try {
         $oRPProfileResponse = $oPaypalService->CreateRecurringPaymentsProfile($oRPProfileReq);
     } catch (Exception $oException) {
         $this->_logException($oException);
         exit;
     }
     $sResultMessage = '_bx_sites_paypal_err_subscribe';
     if (!isset($oRPProfileResponse)) {
         $sLog = "---\n";
         $sLog .= "--- Create Recurring: {date}\n";
         $sLog .= "--- Request: " . $oPaypalService->getLastRequest() . "\n";
         $sLog .= "--- Response: " . $oPaypalService->getLastResponse() . "\n";
         $sLog .= "---\n";
         $this->_logError($sLog);
         return $sResultMessage;
     }
     $sLog = "---\n";
     $sLog .= "--- Create Recurring: {date}\n";
     $sLog .= "--- Status: " . $oRPProfileResponse->Ack . "\n";
     $sLog .= "--- Profile ID: " . $oRPProfileResponse->CreateRecurringPaymentsProfileResponseDetails->ProfileID;
     $this->_logNote($sLog);
     $this->_logNote($oRPProfileResponse);
     $this->_logNote("---\n");
     if ($oRPProfileResponse->Ack == 'Success') {
         $sProfileId = $oRPProfileResponse->CreateRecurringPaymentsProfileResponseDetails->ProfileID;
         $oAccount = $this->_oModule->getObject('Account');
         $oAccount->onProfileCreated($sProfileId, $sTocken);
         $sResultMessage = '_bx_sites_paypal_msg_subscribe';
     }
     return $sResultMessage;
 }
 public function purchase_direct_recurring($product)
 {
     //create a recurring payment profile
     $person_name = new PersonNameType();
     $person_name->FirstName = $_POST['first_name'];
     $person_name->LastName = $_POST['last_name'];
     $payer = new PayerInfoType();
     $payer->Payer = $_POST['email'];
     $payer->PayerName = $person_name;
     $card_details = new CreditCardDetailsType();
     $card_details->CreditCardNumber = $_POST['cc_number'];
     $card_details->CreditCardType = $_POST['cc_type'];
     $card_details->ExpMonth = $_POST['cc_expmonth'];
     $card_details->ExpYear = $_POST['cc_expyear'] + 2000;
     $card_details->CVV2 = $_POST['cc_cvc'];
     $card_details->CardOwner = $payer;
     $activation_details = new ActivationDetailsType();
     $activation_details->FailedInitialAmountAction = 'ContinueOnFailure';
     $activation_details->InitialAmount = new BasicAmountType($product['currency'], $product['init_amount']);
     if (empty($product['init_amount'])) {
         $activation_details->InitialAmount = new BasicAmountType($product['currency'], $product['recur_amount']);
     }
     $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"));
     $schedule_details->ActivationDetails = $activation_details;
     $recur_profile_details = new RecurringPaymentsProfileDetailsType();
     // adjust the start billing date to the next period
     $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_paypay_profile_details->CreditCard = $card_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;
     $paypal_service = new PayPalAPIInterfaceServiceService($this->pp_settings);
     $create_profile_resp = $paypal_service->CreateRecurringPaymentsProfile($create_recur_profile_req);
     if ($create_profile_resp->Ack != 'Success' && $create_profile_resp->Ack != 'SuccessWithWarning') {
         return false;
     }
     if ($create_profile_resp->CreateRecurringPaymentsProfileResponseDetails->ProfileStatus == 'ActiveProfile') {
         return array('status' => 'active', 'id' => $create_profile_resp->CreateRecurringPaymentsProfileResponseDetails->ProfileID);
     }
     return array('status' => 'pending', 'id' => $create_profile_resp->CreateRecurringPaymentsProfileResponseDetails->ProfileID);
 }