CreateRecurringPaymentsProfile() public method

Service Call: CreateRecurringPaymentsProfile
public CreateRecurringPaymentsProfile ( CreateRecurringPaymentsProfileReq $createRecurringPaymentsProfileReq, mixed $apiCredential = null ) : CreateRecurringPaymentsProfileResponseType
$createRecurringPaymentsProfileReq PayPal\PayPalAPI\CreateRecurringPaymentsProfileReq
$apiCredential mixed - Optional API credential - can either be a username configured in sdk_config.ini or a ICredential object created dynamically
return PayPal\PayPalAPI\CreateRecurringPaymentsProfileResponseType
示例#1
0
 /**
  * Create a Paypal recurring payment profile
  *
  * @param array $order          
  * @param string $token         
  * @param array $subscriptionType         
  * @return \PayPalAPI\CreateRecurringPaymentsProfileResponseType
  */
 public function createRecurringPaymentProfile(array $paymentProfile, $token, array $subscriptionType)
 {
     $billingStartDate = Date::getDateTime($paymentProfile['billingStartDate']);
     $RPProfileDetails = new RecurringPaymentsProfileDetailsType();
     $RPProfileDetails->SubscriberName = Session::getCredentials()->getUsername();
     // This should be passed in
     $RPProfileDetails->BillingStartDate = $billingStartDate->format(\DateTime::ATOM);
     $RPProfileDetails->ProfileReference = $paymentProfile['userId'] . '-' . $paymentProfile['orderId'];
     $paymentBillingPeriod = new BillingPeriodDetailsType();
     $paymentBillingPeriod->BillingFrequency = $paymentProfile['billingFrequency'];
     $paymentBillingPeriod->BillingPeriod = $paymentProfile['billingPeriod'];
     $paymentBillingPeriod->Amount = new BasicAmountType($paymentProfile['currency'], $paymentProfile['amount']);
     $scheduleDetails = new ScheduleDetailsType();
     $scheduleDetails->Description = $subscriptionType['agreement'];
     $scheduleDetails->PaymentPeriod = $paymentBillingPeriod;
     $createRPProfileRequestDetail = new CreateRecurringPaymentsProfileRequestDetailsType();
     $createRPProfileRequestDetail->Token = $token;
     $createRPProfileRequestDetail->ScheduleDetails = $scheduleDetails;
     $createRPProfileRequestDetail->RecurringPaymentsProfileDetails = $RPProfileDetails;
     $createRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
     $createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetail;
     $createRPProfileReq = new CreateRecurringPaymentsProfileReq();
     $createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;
     $paypalService = new PayPalAPIInterfaceServiceService();
     return $paypalService->CreateRecurringPaymentsProfile($createRPProfileReq);
 }
 /**
  * PayPal confirm OTO URL
  */
 public function getPaypalConfirmOto()
 {
     // Add third party libraries
     require_once app_path() . "/libraries/Curl/Curl.php";
     // Add Curl library
     $product = Session::get('_product');
     $plan = Session::get('_plan');
     $buyer = Session::get('_buyer');
     // Create Buyer Account
     $buyer = Buyer::where('id', '=', $buyer)->first();
     $email = $buyer->email;
     $first_name = $buyer->first_name;
     $last_name = $buyer->last_name;
     // Get product and plan data
     $product = Product::where('id', '=', $product)->first();
     $plan = Plan::where('id', '=', $plan)->first();
     $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'));
     // Payment is charged, now create recurring profile if it is recurring product
     if ($plan->is_recurring) {
         $currencyCode = "USD";
         /*
          *  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();
         $RPProfileDetails->SubscriberName = $first_name . ' ' . $last_name;
         //$_REQUEST['subscriberName'];
         // Y-m-d\TH:i:sP
         $time_after_30_days = time() + 86400 * 30 * $plan->recurring_freq;
         //$time_after_30_days = time();
         $billing_start_date = date(DATE_ATOM, $time_after_30_days);
         $RPProfileDetails->BillingStartDate = $billing_start_date;
         //$_REQUEST['billingStartDate'];
         //$RPProfileDetails->SubscriberShippingAddress  = $shippingAddress;
         $activationDetails = new ActivationDetailsType();
         /*
          * (Optional) Initial non-recurring payment amount due immediately upon profile creation. Use an initial amount for enrolment or set-up fees.
          */
         //$activationDetails->InitialAmount = new BasicAmountType($currencyCode, $plan->setup_fee); //$_REQUEST['initialAmount']
         /*
         			 *  (Optional) Action you can specify when a payment fails. It is one of the following values:
            ContinueOnFailure – By default, PayPal suspends the pending profile in the event that the initial payment amount fails. You can override this default behavior by setting this field to ContinueOnFailure. Then, if the initial payment amount fails, PayPal adds the failed payment amount to the outstanding balance for this recurring payment profile.
            When you specify ContinueOnFailure, a success code is returned to you in the CreateRecurringPaymentsProfile response and the recurring payments profile is activated for scheduled billing immediately. You should check your IPN messages or PayPal account for updates of the payment status.
            CancelOnFailure – If this field is not set or you set it to CancelOnFailure, PayPal creates the recurring payment profile, but places it into a pending status until the initial payment completes. If the initial payment clears, PayPal notifies you by IPN that the pending profile has been activated. If the payment fails, PayPal notifies you by IPN that the pending profile has been canceled.
         */
         //$activationDetails->FailedInitialAmountAction = $_REQUEST['failedInitialAmountAction'];
         /*
          *  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`
         */
         $paymentBillingPeriod = new BillingPeriodDetailsType();
         $paymentBillingPeriod->BillingFrequency = $plan->recurring_freq;
         //$_REQUEST['billingFrequency'];
         $paymentBillingPeriod->BillingPeriod = 'Month';
         //$_REQUEST['billingPeriod'];
         //$paymentBillingPeriod->TotalBillingCycles = $_REQUEST['totalBillingCycles'];
         $paymentBillingPeriod->Amount = new BasicAmountType($currencyCode, $plan->price);
         //$_REQUEST['paymentAmount']
         //$paymentBillingPeriod->ShippingAmount = new BasicAmountType($currencyCode, $_REQUEST['paymentShippingAmount']);
         //$paymentBillingPeriod->TaxAmount = new BasicAmountType($currencyCode, $_REQUEST['paymentTaxAmount']);
         /*
          * 	 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();
         $scheduleDetails->Description = $product->name . " - " . $plan->name;
         //$_REQUEST['profileDescription'];
         $scheduleDetails->ActivationDetails = $activationDetails;
         // if( $_REQUEST['trialBillingFrequency'] != "" && $_REQUEST['trialAmount'] != "") {
         // 	$trialBillingPeriod =  new BillingPeriodDetailsType();
         // 	$trialBillingPeriod->BillingFrequency = $_REQUEST['trialBillingFrequency'];
         // 	$trialBillingPeriod->BillingPeriod = $_REQUEST['trialBillingPeriod'];
         // 	$trialBillingPeriod->TotalBillingCycles = $_REQUEST['trialBillingCycles'];
         // 	$trialBillingPeriod->Amount = new BasicAmountType($currencyCode, $_REQUEST['trialAmount']);
         // 	$trialBillingPeriod->ShippingAmount = new BasicAmountType($currencyCode, $_REQUEST['trialShippingAmount']);
         // 	$trialBillingPeriod->TaxAmount = new BasicAmountType($currencyCode, $_REQUEST['trialTaxAmount']);
         // 	$scheduleDetails->TrialPeriod  = $trialBillingPeriod;
         // }
         $scheduleDetails->PaymentPeriod = $paymentBillingPeriod;
         // $scheduleDetails->MaxFailedPayments =  $_REQUEST['maxFailedPayments'];
         // $scheduleDetails->AutoBillOutstandingAmount = $_REQUEST['autoBillOutstandingAmount'];
         /*
          * 	 `CreateRecurringPaymentsProfileRequestDetailsType` which takes
         mandatory params:
         
         * `Recurring Payments Profile Details`
         * `Schedule Details`
         */
         $createRPProfileRequestDetail = new CreateRecurringPaymentsProfileRequestDetailsType();
         if (trim($_REQUEST['token']) != "") {
             $createRPProfileRequestDetail->Token = $_REQUEST['token'];
         }
         $createRPProfileRequestDetail->ScheduleDetails = $scheduleDetails;
         $createRPProfileRequestDetail->RecurringPaymentsProfileDetails = $RPProfileDetails;
         $createRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
         $createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetail;
         $createRPProfileReq = new CreateRecurringPaymentsProfileReq();
         $createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;
         /*
          *  ## 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($config);
         try {
             /* wrap API method calls on the service object with a try catch */
             $createRPProfileResponse = $paypalService->CreateRecurringPaymentsProfile($createRPProfileReq);
         } catch (Exception $ex) {
             echo "Error occured while charging for PayPal. Please try again later";
             exit;
         }
         if (isset($createRPProfileResponse)) {
             /*echo "<table>";
             				echo "<tr><td>Ack :</td><td><div id='Ack'>$createRPProfileResponse->Ack</div> </td></tr>";
             				echo "<tr><td>ProfileID :</td><td><div id='ProfileID'>".$createRPProfileResponse->CreateRecurringPaymentsProfileResponseDetails->ProfileID ."</div> </td></tr>";
             				echo "</table>";
             
             				echo "<pre>";
             				print_r($createRPProfileResponse);
             				echo "</pre>";*/
             if (!empty($createRPProfileResponse->Ack) and $createRPProfileResponse->Ack == 'Success') {
                 if ($createRPProfileResponse->CreateRecurringPaymentsProfileResponseDetails->ProfileStatus == 'ActiveProfile') {
                     $paypal_sub_id = $createRPProfileResponse->CreateRecurringPaymentsProfileResponseDetails->ProfileID;
                 } else {
                     echo "Error occured while charging for PayPal. Please try again later";
                     exit;
                 }
             } else {
                 echo "Error occured while charging for PayPal. Please try again later";
                 exit;
             }
         } else {
             echo "Error occured while charging for PayPal. Please try again later";
             exit;
         }
     }
     /*
      * The DoExpressCheckoutPayment API operation completes an Express Checkout transaction. If you set up a billing agreement in your SetExpressCheckout API call, the billing agreement is created when you call the DoExpressCheckoutPayment API operatio
      */
     /*
      * 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.
      * For digital goods, the following must be true:
      * total cost > 0
      * total cost <= total cost passed in the call to SetExpressCheckout
      */
     $token = urlencode($_REQUEST['token']);
     /*
      *  Unique PayPal buyer account identification number as returned in the GetExpressCheckoutDetails response
      */
     $payerId = urlencode($_REQUEST['PayerID']);
     $paymentAction = "Sale";
     //urlencode(  $_REQUEST['paymentAction']);
     // ------------------------------------------------------------------
     // this section is optional if parameters required for DoExpressCheckout is retrieved from your database
     $getExpressCheckoutDetailsRequest = new PayPal\PayPalAPI\GetExpressCheckoutDetailsRequestType($token);
     $getExpressCheckoutReq = new PayPal\PayPalAPI\GetExpressCheckoutDetailsReq();
     $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
     // ------------------------------------------------------------------
     // this section get checkout data from PayPal
     $getExpressCheckoutDetailsRequest = new PayPal\PayPalAPI\GetExpressCheckoutDetailsRequestType($token);
     $getExpressCheckoutReq = new PayPal\PayPalAPI\GetExpressCheckoutDetailsReq();
     $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
     /*
     Configuration::getAcctAndConfig() returns array that contains credential and config parameters
     */
     $paypalService = new PayPal\Service\PayPalAPIInterfaceServiceService($config);
     try {
         /* wrap API method calls on the service object with a try catch */
         $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
     } catch (Exception $ex) {
         echo "Error occured while charging for PayPal";
         exit;
     }
     //----------------------------------------------------------------------------
     try {
         /* wrap API method calls on the service object with a try catch */
         $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
     } catch (Exception $ex) {
         echo "Error occured while charging for PayPal";
         exit;
     }
     if (isset($getECResponse)) {
         $amount = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails[0]->OrderTotal->value;
     }
     /*
      * 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 PayPal\CoreComponentTypes\BasicAmountType();
     $orderTotal->currencyID = 'USD';
     $orderTotal->value = $amount;
     //$_REQUEST['amt'];
     $paymentDetails = new PayPal\EBLBaseComponents\PaymentDetailsType();
     $paymentDetails->OrderTotal = $orderTotal;
     /*
      * 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.
      */
     $paymentDetails->NotifyURL = Config::get('project.paypal_ipn_url');
     $DoECRequestDetails = new PayPal\EBLBaseComponents\DoExpressCheckoutPaymentRequestDetailsType();
     $DoECRequestDetails->PayerID = $payerId;
     $DoECRequestDetails->Token = $token;
     $DoECRequestDetails->PaymentAction = $paymentAction;
     $DoECRequestDetails->PaymentDetails[0] = $paymentDetails;
     $DoECRequest = new PayPal\PayPalAPI\DoExpressCheckoutPaymentRequestType();
     $DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
     $DoECReq = new PayPal\PayPalAPI\DoExpressCheckoutPaymentReq();
     $DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
     try {
         /* wrap API method calls on the service object with a try catch */
         $DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
     } catch (Exception $ex) {
         echo "Error occured while charging for PayPal";
         exit;
     }
     if (isset($DoECResponse)) {
         // Get Transaction ID
         if (!empty($DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->TransactionID)) {
             $transaction_id = $DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->TransactionID;
         } else {
             Log::info('PayPal EC Confirm failed', array('buyer' => $buyer, 'product' => $product->id, 'plan' => $plan->id, 'COData' => $DoECResponse));
             // Redirect back them to PayPal with token
             return Redirect::to(Config::get('project.paypal_api_url') . 'cgi-bin/webscr?cmd=_express-checkout&token=' . trim($_REQUEST['token']));
         }
         // Update Buyer IP
         Buyer::updateLastIP($buyer);
         // Get Purchase ID
         $purchase = Purchase::where('product_id', '=', $product->id)->where('buyer_id', '=', $buyer->id)->first();
         // If we successfully get the recurring ID
         if (!empty($paypal_sub_id)) {
             $purchase->paypal_sub_id = $paypal_sub_id;
             $purchase->save();
         }
         // Push data using own IPN
         $ipn_url = Config::get('project.paypal_ipn_url');
         $data_curl = array("dk_new_charge" => TRUE, "transaction_id" => $transaction_id, "buyer_id" => $buyer->id, "plan_id" => $plan->id, "product_id" => $product->id, "amount" => $amount);
         $curl = new Curl();
         $curl->simple_post($ipn_url, $data_curl, array(CURLOPT_BUFFERSIZE => 10));
         // Everything is ok, now remove session data
         // for security purpose
         Session::forget('_product');
         Session::forget('_plan');
         Session::forget('_buyer');
         // Redirect
         $url = url('checkout/thanks?url=' . $plan->next_page_url . '&code=' . $product->code);
         return Redirect::to($url);
         //return Redirect::to($plan->next_page_url);
     }
 }
    $createRPProfileRequestDetail->CreditCard = $creditCard;
}
$createRPProfileRequestDetail->ScheduleDetails = $scheduleDetails;
$createRPProfileRequestDetail->RecurringPaymentsProfileDetails = $RPProfileDetails;
$createRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
$createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetail;
$createRPProfileReq = new CreateRecurringPaymentsProfileReq();
$createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;
/*
 *  ## 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 */
    $createRPProfileResponse = $paypalService->CreateRecurringPaymentsProfile($createRPProfileReq);
} catch (Exception $ex) {
    include_once "../Error.php";
    exit;
}
if (isset($createRPProfileResponse)) {
    echo "<table>";
    echo "<tr><td>Ack :</td><td><div id='Ack'>{$createRPProfileResponse->Ack}</div> </td></tr>";
    echo "<tr><td>ProfileID :</td><td><div id='ProfileID'>" . $createRPProfileResponse->CreateRecurringPaymentsProfileResponseDetails->ProfileID . "</div> </td></tr>";
    echo "</table>";
    echo "<pre>";
    print_r($createRPProfileResponse);
    echo "</pre>";
}
require_once '../Response.php';
示例#4
0
 /**
  * @param string $token
  * @param $reference
  * @param $subscriberName
  * @param \DateTime $billingStartDate
  * @param array $subscriptionType
  * @return string $paymentProfileId
  */
 public function createRecurringPaymentProfile($token, $reference, $subscriberName, \DateTime $billingStartDate, array $subscriptionType)
 {
     $paymentProfileId = null;
     $amount = $subscriptionType['amount'];
     $agreement = $subscriptionType['agreement'];
     $currency = Config::$a['commerce']['currency'];
     $RPProfileDetails = new RecurringPaymentsProfileDetailsType();
     $RPProfileDetails->SubscriberName = $subscriberName;
     $RPProfileDetails->BillingStartDate = $billingStartDate->format(\DateTime::ATOM);
     $RPProfileDetails->ProfileReference = $reference;
     $paymentBillingPeriod = new BillingPeriodDetailsType();
     $paymentBillingPeriod->BillingFrequency = $subscriptionType['billingFrequency'];
     $paymentBillingPeriod->BillingPeriod = $subscriptionType['billingPeriod'];
     $paymentBillingPeriod->Amount = new BasicAmountType($currency, $amount);
     $scheduleDetails = new ScheduleDetailsType();
     $scheduleDetails->Description = $agreement;
     $scheduleDetails->PaymentPeriod = $paymentBillingPeriod;
     $createRPProfileRequestDetail = new CreateRecurringPaymentsProfileRequestDetailsType();
     $createRPProfileRequestDetail->Token = $token;
     $createRPProfileRequestDetail->ScheduleDetails = $scheduleDetails;
     $createRPProfileRequestDetail->RecurringPaymentsProfileDetails = $RPProfileDetails;
     $createRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
     $createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetail;
     $createRPProfileReq = new CreateRecurringPaymentsProfileReq();
     $createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;
     $paypalService = new PayPalAPIInterfaceServiceService();
     $createRPProfileResponse = $paypalService->CreateRecurringPaymentsProfile($createRPProfileReq);
     if (isset($createRPProfileResponse) && $createRPProfileResponse->Ack == 'Success') {
         $paymentProfileId = $createRPProfileResponse->CreateRecurringPaymentsProfileResponseDetails->ProfileID;
     }
     return $paymentProfileId;
 }