GetRecurringPaymentsProfileDetails() public method

Service Call: GetRecurringPaymentsProfileDetails
public GetRecurringPaymentsProfileDetails ( GetRecurringPaymentsProfileDetailsReq $getRecurringPaymentsProfileDetailsReq, mixed $apiCredential = null ) : GetRecurringPaymentsProfileDetailsResponseType
$getRecurringPaymentsProfileDetailsReq PayPal\PayPalAPI\GetRecurringPaymentsProfileDetailsReq
$apiCredential mixed - Optional API credential - can either be a username configured in sdk_config.ini or a ICredential object created dynamically
return PayPal\PayPalAPI\GetRecurringPaymentsProfileDetailsResponseType
Exemplo n.º 1
0
 /**
  * Clear a payment profile
  *
  * @param array $subscription         
  * @param array $paymentProfile         
  * @throws Exception
  */
 public function cancelPaymentProfile(array $subscription, array $paymentProfile)
 {
     $subService = SubscriptionsService::instance();
     $orderService = OrdersService::instance();
     // PPService
     $paypalService = new PayPalAPIInterfaceServiceService();
     $getRPPDetailsReqest = new GetRecurringPaymentsProfileDetailsRequestType();
     $getRPPDetailsReqest->ProfileID = $paymentProfile['paymentProfileId'];
     $getRPPDetailsReq = new GetRecurringPaymentsProfileDetailsReq();
     $getRPPDetailsReq->GetRecurringPaymentsProfileDetailsRequest = $getRPPDetailsReqest;
     $getRPPDetailsResponse = $paypalService->GetRecurringPaymentsProfileDetails($getRPPDetailsReq);
     if (empty($getRPPDetailsResponse) || $getRPPDetailsResponse->Ack != 'Success') {
         throw new Exception('Error retrieving payment profile status');
     }
     $profileStatus = $getRPPDetailsResponse->GetRecurringPaymentsProfileDetailsResponseDetails->ProfileStatus;
     // Active profile, send off the cancel
     if (strcasecmp($profileStatus, PaymentProfileStatus::ACTIVEPROFILE) === 0 || strcasecmp($profileStatus, PaymentProfileStatus::CANCELLEDPROFILE) === 0) {
         if (strcasecmp($profileStatus, PaymentProfileStatus::ACTIVEPROFILE) === 0) {
             // Do we have a payment profile, we need to cancel it with paypal
             $manageRPPStatusReqestDetails = new ManageRecurringPaymentsProfileStatusRequestDetailsType();
             $manageRPPStatusReqestDetails->Action = 'Cancel';
             $manageRPPStatusReqestDetails->ProfileID = $paymentProfile['paymentProfileId'];
             $manageRPPStatusReqest = new ManageRecurringPaymentsProfileStatusRequestType();
             $manageRPPStatusReqest->ManageRecurringPaymentsProfileStatusRequestDetails = $manageRPPStatusReqestDetails;
             $manageRPPStatusReq = new ManageRecurringPaymentsProfileStatusReq();
             $manageRPPStatusReq->ManageRecurringPaymentsProfileStatusRequest = $manageRPPStatusReqest;
             $manageRPPStatusResponse = $paypalService->ManageRecurringPaymentsProfileStatus($manageRPPStatusReq);
             if (!isset($manageRPPStatusResponse) || $manageRPPStatusResponse->Ack != 'Success') {
                 throw new Exception($manageRPPStatusResponse->Errors[0]->LongMessage);
             }
         }
         $orderService->updatePaymentProfileState($paymentProfile['profileId'], PaymentProfileStatus::CANCELLEDPROFILE);
     }
 }
 /**
  * Cancel Subscription
  */
 public function getCancelSubscription($id, $at_period_end = FALSE)
 {
     // Page Title
     $this->_data['page_title'] = "Cancel Subscription";
     $transaction = Transaction::find($id);
     $this->_data['transaction'] = $transaction;
     $pay_id = $transaction->pay_id;
     $pay_method = DKHelpers::GetPayMethod($pay_id);
     // If Stripe
     if ($pay_method == 'Stripe') {
         $plan_id = $transaction->plan->stripe_id;
         $stripe_sub_id = NULL;
         $is_stripe_sub_active = 0;
         // Add Stripe library
         require_once app_path() . "/libraries/stripe-php-1.9.0/lib/Stripe.php";
         // Add Stripe library
         Stripe::setApiKey(Config::get('project.stripe_secret_key'));
         try {
             $ch = Stripe_Charge::retrieve($pay_id);
             $subscriptions = Stripe_Customer::retrieve($ch->customer)->subscriptions->all(array('count' => 100));
             foreach ($subscriptions->data as $subscription) {
                 if ($subscription->plan->id == $plan_id) {
                     $stripe_sub_id = $subscription->id;
                     if ($subscription->status == 'active') {
                         $is_stripe_sub_active = 1;
                     }
                     break;
                 }
             }
             $this->_data['stripe_customer_id'] = $ch->customer;
         } catch (Exception $e) {
             Session::flash('alert_error', '<strong>Ooops!</strong> Subscription was not retreived, try again.');
             return Redirect::to("admin/transactions/detail/{$transaction->id}");
         }
     }
     // If PayPal
     if ($pay_method == 'PayPal') {
         $paypal_sub_id = NULL;
         $is_paypal_sub_active = 0;
         $purchase = $transaction->purchase;
         $paypal_sub_id = $purchase->paypal_sub_id;
         $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'));
         /*
          * Obtain information about a recurring payments profile. 
          */
         $getRPPDetailsReqest = new GetRecurringPaymentsProfileDetailsRequestType();
         /*
          * (Required) Recurring payments profile ID returned in the CreateRecurringPaymentsProfile response. 19-character profile IDs are supported for compatibility with previous versions of the PayPal API.
          */
         $getRPPDetailsReqest->ProfileID = $paypal_sub_id;
         $getRPPDetailsReq = new GetRecurringPaymentsProfileDetailsReq();
         $getRPPDetailsReq->GetRecurringPaymentsProfileDetailsRequest = $getRPPDetailsReqest;
         /*
          * 	 ## 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 */
             $getRPPDetailsResponse = $paypalService->GetRecurringPaymentsProfileDetails($getRPPDetailsReq);
         } catch (Exception $ex) {
             Session::flash('alert_error', '<strong>Ooops!</strong> Subscription was not retreived, try again.');
             return Redirect::to("admin/transactions/detail/{$transaction->id}");
         }
         if (isset($getRPPDetailsResponse) and $getRPPDetailsResponse->Ack == 'Success') {
             $status = $getRPPDetailsResponse->GetRecurringPaymentsProfileDetailsResponseDetails->ProfileStatus;
             if ($status == 'ActiveProfile') {
                 $is_paypal_sub_active = 1;
             }
         }
         //exit;
     }
     $this->_data['subscription_id'] = $pay_method == 'Stripe' ? $stripe_sub_id : $paypal_sub_id;
     $this->_data['is_sub_active'] = $pay_method == 'Stripe' ? $is_stripe_sub_active : $is_paypal_sub_active;
     $this->_data['at_period_end'] = $at_period_end;
     $this->_data['pay_method'] = $pay_method;
     return View::make('admin.transactions.cancel-subscription', $this->_data)->nest('header', 'admin.common.header', $this->_data)->nest('footer', 'admin.common.footer', $this->_data);
 }
 */
$getRPPDetailsReqest = new GetRecurringPaymentsProfileDetailsRequestType();
/*
 * (Required) Recurring payments profile ID returned in the CreateRecurringPaymentsProfile response. 19-character profile IDs are supported for compatibility with previous versions of the PayPal API.
 */
$getRPPDetailsReqest->ProfileID = $_REQUEST['profileID'];
$getRPPDetailsReq = new GetRecurringPaymentsProfileDetailsReq();
$getRPPDetailsReq->GetRecurringPaymentsProfileDetailsRequest = $getRPPDetailsReqest;
/*
 * 	 ## 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 */
    $getRPPDetailsResponse = $paypalService->GetRecurringPaymentsProfileDetails($getRPPDetailsReq);
} catch (Exception $ex) {
    include_once "../Error.php";
    exit;
}
if (isset($getRPPDetailsResponse)) {
    echo "<table>";
    echo "<tr><td>Ack :</td><td><div id='Ack'>{$getRPPDetailsResponse->Ack}</div> </td></tr>";
    echo "<tr><td>ProfileID :</td><td><div id='ProfileID'>" . $getRPPDetailsResponse->GetRecurringPaymentsProfileDetailsResponseDetails->ProfileID . "</div> </td></tr>";
    echo "</table>";
    echo "<pre>";
    print_r($getRPPDetailsResponse);
    echo "</pre>";
}
require_once '../Response.php';