public ManageRecurringPaymentsProfileStatus ( |
||
$manageRecurringPaymentsProfileStatusReq | ||
$apiCredential | mixed | - Optional API credential - can either be a username configured in sdk_config.ini or a ICredential object created dynamically |
return | PayPal\PayPalAPI\ManageRecurringPaymentsProfileStatusResponseType |
public function ManageRecurringPaymentsProfileStatus($manageRecurringPaymentsProfileStatusReq, $apiCredential = null)
{
$apiContext = new PPApiContext($this->config);
$handlers = array(new PPMerchantServiceHandler($apiCredential, self::$SDK_NAME, self::$SDK_VERSION));
$this->setStandardParams($manageRecurringPaymentsProfileStatusReq->ManageRecurringPaymentsProfileStatusRequest);
$ret = new ManageRecurringPaymentsProfileStatusResponseType();
$resp = $this->call('PayPalAPIAA', 'ManageRecurringPaymentsProfileStatus', $manageRecurringPaymentsProfileStatusReq, $apiContext, $handlers);
$ret->init(PPUtils::xmlToArray($resp));
return $ret;
}
/** * 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); } }