function test() { $pipeline = new Amazon_CBUI_CBUIRecurringTokenPipeline(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY); $pipeline->setMandatoryParameters("callerReferenceRecurringToken", "http://www.mysite.com/call_back.jsp", "5", "1 Month"); //Optional parameters $pipeline->addParameter("paymentMethod", "CC"); //accept only credit card payments $pipeline->addParameter("paymentReason", "Monthly subscription of Times magazine"); //RecurringToken url print "Sample CBUI url for RecurringToken pipeline : " . $pipeline->getUrl() . "\n"; }
/** * Send a request for recurring payment authorization to Amazon. * * This function creates a userBillingActionId and initiates the payment request process using Amazon FPS CBUI (Co-branded User Interface). * 1. Establishes the recurring payment pipeline with the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. * 2. Sets mandatory parameters to be sent to Amazon like callerReference, PAYMENT_RETURN_URL, transactionAmount, recurringPeriod (1 Day(s), Month(s)), and paymentReason (the name of the plan, i.e. Project Monthly). * 3. The parameters are url-encoded to be sent to Amazon. * 4. The request is saved in the database. * This uses the Amazon API to perform the heavy lifting. * After the user authorizes payment, Amazon sends the user back to ADRList.com. * There are three more steps to actually recieve payment - validate the return response, make a pay request, and capture the IPN response. * * @author Mark O'Russa <*****@*****.**> * @param int $userId Request authorization for this user. * @param int $billingOfferId The billing offer, for example Project Monthly. Refers to the billingOffers table. * * @returns string The return url supplied to Amazon, otherwise false. */ public static function amazonAuthorization($userId, $billingOfferId) { global $debug, $Dbc; try { if (empty($userId)) { throw new Adrlist_CustomException('', '$userId is empty.'); } elseif (!is_numeric($userId)) { throw new Adrlist_CustomException('', '$userId is not numeric.'); } elseif (empty($billingOfferId)) { throw new Adrlist_CustomException('', '$billingOfferId is empty.'); } elseif (!is_numeric($billingOfferId)) { throw new Adrlist_CustomException('', '$billingOfferId is not numeric.'); } $Dbc->beginTransaction(); //Get the plan info. $planInfo = self::getPlanInfo($billingOfferId); if (empty($planInfo)) { throw new Adrlist_CustomException('', '$planInfo is empty.'); } elseif ($planInfo['endDate'] && strtotime($planInfo['endDate']) < TIMESTAMP) { //If the endDate is not null and has expired. throw new Adrlist_CustomException('The plan you selected has expired. Please select a different plan.', 'The endDate for billingOfferId ' . $billingOfferId . 'has expired.'); } //Add a billing action. $callerReference = self::addBillingAction($userId, $billingOfferId, 1, 1, __FILE__ . ' ' . __LINE__); /*Start an entry in the database. $cbuiRequestsStmt = $Dbc->prepare("INSERT INTO amazonCBUIRequests SET userBillingActionId = ?, aDatetime = ?"); $cbuiRequestsStmt->execute(array($userBillingActionId,DATETIME)); $callerReference = $Dbc->lastInsertId();*/ //Create the url with CBUI parameters. $period = ucfirst($planInfo['period']); $transactionAmount = trim($planInfo['price']); $recurringPeriod = $planInfo['length'] > 1 ? $planInfo['length'] . ' ' . $period . 's' : $planInfo['length'] . ' ' . $period; $recurringPeriod = $recurringPeriod == '1 Year' ? '12 Months' : $recurringPeriod; if (LOCAL) { $returnUrl = LINKMYACCOUNT . '/paymentAuthorization.php'; } else { $returnUrl = 'https://' . DOMAIN . '/myAccount/paymentAuthorization.php'; } $request = new Amazon_CBUI_CBUIRecurringTokenPipeline(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY); $request->setMandatoryParameters($callerReference, $returnUrl, $transactionAmount, $recurringPeriod); $request->addParameter('paymentReason', $planInfo['name']); $url = $request->getUrl(); $debug->add('$url: ' . $url); $urlParts = parse_url($url); $debug->printArray($urlParts, '$urlParts'); parse_str($urlParts['query'], $queryArray); $debug->printArray($queryArray, '$queryArray'); /*Finish inserting the request in the database. $finishCbuiRequestStmt = $Dbc->prepare("UPDATE amazonCBUIRequests SET apiVersion = ?, callerKey = ?, paymentReason = ?, pipelineName = ?, returnUrl = ?, signature = ?, signatureMethod = ?, signatureVersion = ?, transactionAmount = ?, url = ? WHERE callerReference = ?"); $finishCbuiRequestParams = array( $queryArray['version'], $queryArray['callerKey'], $queryArray['paymentReason'], $queryArray['pipelineName'], $queryArray['returnURL'], $queryArray['signature'], $queryArray['signatureMethod'], $queryArray['signatureVersion'], $queryArray['transactionAmount'], $url, $queryArray['callerReference'] ); $finishCbuiRequestStmt->execute($finishCbuiRequestParams);*/ $Dbc->commit(); } catch (Adrlist_CustomException $e) { } catch (PDOException $e) { $debug->add('<pre>' . $e . '</pre>'); error(__LINE__, '', ''); } return empty($url) ? false : $url; }