/** * Overloads the base class's get_payment_details_url to map the subscription details * to the PayPal NVP format for posting to PayPal. * * The function first calls the Parent's get_payment_details_url, which takes care of * common NVP fields, like API credentials. It then appends subscription related fields. * * Note: The SetExpressCheckout action URL is partially built in the base class as it contains * NVP fields common to both Purchases & Subscriptions. * * @param $action, string. The PayPal NVP API action to create the URL for. One of SetExpressCheckout, DoExpressCheckoutPayment or GetTransactionDetails. * @param $transaction_id, (optional) string. A PayPal Transaction ID, required for the GetTransactionDetails operation. * @return string A URI which can be use in the @see call_paypal() method to perform the appropriate API operation. */ protected function get_payment_details_url($action, $transaction_id = '') { // Setup the Payment Details $api_request = parent::get_payment_details_url($action, $transaction_id); // Parameters to Request Recurring Payment Token if ('SetExpressCheckout' == $action) { $api_request .= '&PAYMENTREQUEST_0_CURRENCYCODE=' . urlencode($this->currency) . '&PAYMENTREQUEST_0_PAYMENTACTION=Sale' . '&PAYMENTREQUEST_0_AMT=' . $this->purchase->amount . '&PAYMENTREQUEST_0_ITEMAMT=' . ($this->purchase->amount - $this->purchase->tax_amount) . '&PAYMENTREQUEST_0_TAXAMT=' . $this->purchase->tax_amount . '&PAYMENTREQUEST_0_DESC=' . urlencode($this->purchase->description); // (Optional) Description of items the buyer is purchasing. // Maybe add an Invoice number if (!empty($this->purchase->invoice_number)) { $api_request .= '&PAYMENTREQUEST_0_INVNUM=' . $this->purchase->invoice_number; } // (Optional) Your own invoice or tracking number. // Maybe add an IPN URL if (!empty($this->notify_url)) { $api_request .= '&PAYMENTREQUEST_0_NOTIFYURL=' . urlencode($this->notify_url); } // Maybe add a custom field if (!empty($this->purchase->custom)) { $api_request .= '&PAYMENTREQUEST_0_CUSTOM=' . urlencode($this->purchase->custom); } // Item details $item_count = 0; foreach ($this->purchase->items as $item) { $api_request .= '&L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_count . '=Digital' . '&L_PAYMENTREQUEST_0_NAME' . $item_count . '=' . urlencode($item['item_name']) . '&L_PAYMENTREQUEST_0_AMT' . $item_count . '=' . $item['item_amount'] . '&L_PAYMENTREQUEST_0_QTY' . $item_count . '=' . $item['item_quantity']; if (!empty($item['item_description'])) { $api_request .= '&L_PAYMENTREQUEST_0_DESC' . $item_count . '=' . urlencode($item['item_description']); } if (!empty($item['item_tax'])) { $api_request .= '&L_PAYMENTREQUEST_0_TAXAMT' . $item_count . '=' . $item['item_tax']; } if (!empty($item['item_number'])) { $api_request .= '&L_PAYMENTREQUEST_0_NUMBER' . $item_count . '=' . $item['item_number']; } $item_count++; } } elseif ('DoExpressCheckoutPayment' == $action) { $api_request .= '&METHOD=DoExpressCheckoutPayment' . '&TOKEN=' . $this->token . '&PAYERID=' . $_GET['PayerID'] . '&PAYMENTREQUEST_0_CURRENCYCODE=' . urlencode($this->currency) . '&PAYMENTREQUEST_0_PAYMENTACTION=Sale' . '&PAYMENTREQUEST_0_AMT=' . $this->purchase->amount . '&PAYMENTREQUEST_0_ITEMAMT=' . ($this->purchase->amount - $this->purchase->tax_amount) . '&PAYMENTREQUEST_0_TAXAMT=' . $this->purchase->tax_amount . '&PAYMENTREQUEST_0_DESC=' . urlencode($this->purchase->description); // (Optional) Description of items the buyer is purchasing. // Maybe add an Invoice number if (!empty($this->purchase->invoice_number)) { $api_request .= '&PAYMENTREQUEST_0_INVNUM=' . $this->purchase->invoice_number; } // (Optional) Your own invoice or tracking number. // Maybe add an IPN URL if (!empty($this->notify_url)) { $api_request .= '&PAYMENTREQUEST_0_NOTIFYURL=' . urlencode($this->notify_url); } // Maybe add a custom field if (!empty($this->purchase->custom)) { $api_request .= '&PAYMENTREQUEST_0_CUSTOM=' . urlencode($this->purchase->custom); } // Item details $item_count = 0; foreach ($this->purchase->items as $item) { $api_request .= '&L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_count . '=Digital' . '&L_PAYMENTREQUEST_0_NAME' . $item_count . '=' . urlencode($item['item_name']) . '&L_PAYMENTREQUEST_0_AMT' . $item_count . '=' . $item['item_amount'] . '&L_PAYMENTREQUEST_0_QTY' . $item_count . '=' . $item['item_quantity']; if (!empty($item['item_description'])) { $api_request .= '&L_PAYMENTREQUEST_0_DESC' . $item_count . '=' . urlencode($item['item_description']); } if (!empty($item['item_tax'])) { $api_request .= '&L_PAYMENTREQUEST_0_TAXAMT' . $item_count . '=' . $item['item_tax']; } if (!empty($item['item_number'])) { $api_request .= '&L_PAYMENTREQUEST_0_NUMBER' . $item_count . '=' . $item['item_number']; } $item_count++; } } elseif ('GetTransactionDetails' == $action) { $api_request .= '&METHOD=GetTransactionDetails' . '&TRANSACTIONID=' . urlencode($transaction_id); } return $api_request; }
/** * Overloads the base class's get_payment_details_url to map the subscription details * to the PayPal NVP format for posting to PayPal. * * The function first calls the Parent's get_payment_details_url, which takes care of * common NVP fields, like API credentials. It then appends subscription related fields. * * Note: The SetExpressCheckout action URL is partially built in the base class as it contains * NVP fields common to both Purchases & Subscriptions. * * @param $action, string. The PayPal NVP API action to create the URL for. One of SetExpressCheckout, CreateRecurringPaymentsProfile or GetRecurringPaymentsProfileDetails. * @param $profile_id, (optional) string. A PayPal Recurrent Payment Profile ID, required for GetRecurringPaymentsProfileDetails operation. * @return string A URL which can be called with the @see call_paypal() method to perform the appropriate API operation. */ protected function get_payment_details_url($action, $profile_id = '', $status = '', $args = array()) { // Setup the Payment Details $api_request = parent::get_payment_details_url($action, $profile_id); // Parameters to Request Recurring Payment Token if ('SetExpressCheckout' == $action) { $api_request .= '&L_BILLINGTYPE0=RecurringPayments' . '&L_BILLINGAGREEMENTDESCRIPTION0=' . urlencode($this->subscription->description) . '&CURRENCYCODE=' . urlencode($this->currency) . '&MAXAMT=' . urlencode($this->subscription->average_amount); } elseif ('CreateRecurringPaymentsProfile' == $action) { $api_request .= '&METHOD=CreateRecurringPaymentsProfile' . '&TOKEN=' . $this->token . '&DESC=' . urlencode($this->subscription->description) . '&CURRENCYCODE=' . urlencode($this->currency) . '&PROFILESTARTDATE=' . urlencode($this->subscription->start_date) . '&AMT=' . urlencode($this->subscription->amount) . '&INITAMT=' . urlencode($this->subscription->initial_amount) . '&TAXAMT=' . urlencode($this->subscription->tax_amount) . '&BILLINGPERIOD=' . urlencode($this->subscription->period) . '&BILLINGFREQUENCY=' . urlencode($this->subscription->frequency) . '&TOTALBILLINGCYCLES=' . urlencode($this->subscription->total_cycles) . "&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital" . "&L_PAYMENTREQUEST_0_NAME0=" . urlencode($this->subscription->description) . "&L_PAYMENTREQUEST_0_AMT0=" . urlencode($this->subscription->amount) . "&L_PAYMENTREQUEST_0_QTY0=1"; // Maybe add an Invoice number if (!empty($this->subscription->max_failed_payments)) { $api_request .= '&MAXFAILEDPAYMENTS=' . $this->subscription->max_failed_payments; } // Maybe add an Invoice number if (!empty($this->subscription->invoice_number)) { $api_request .= '&PROFILEREFERENCE=' . $this->subscription->invoice_number; } // (Optional) Your own invoice or tracking number. // Maybe add a trial period if ($this->subscription->trial_frequency > 0 || $this->subscription->trial_total_cycles > 0) { $api_request .= '&TRIALAMT=' . urlencode($this->subscription->trial_amount) . '&TRIALBILLINGPERIOD=' . urlencode($this->subscription->trial_period) . '&TRIALBILLINGFREQUENCY=' . urlencode($this->subscription->trial_frequency) . '&TRIALTOTALBILLINGCYCLES=' . urlencode($this->subscription->trial_total_cycles); } if ($this->subscription->add_to_next_bill == true) { $api_request .= '&AUTOBILLOUTAMT=AddToNextBilling'; } else { $api_request .= '&AUTOBILLOUTAMT=NoAutoBill'; } } elseif ('GetRecurringPaymentsProfileDetails' == $action) { $api_request .= '&METHOD=GetRecurringPaymentsProfileDetails' . '&PROFILEID=' . urlencode($profile_id); } elseif ('ManageRecurringPaymentsProfileStatus' == $action) { $api_request .= '&METHOD=ManageRecurringPaymentsProfileStatus' . '&PROFILEID=' . urlencode($profile_id) . '&ACTION=' . urlencode($status); if (isset($args['note']) && !empty($args['note'])) { $api_request .= '&NOTE=' . urlencode($args['note']); } } return $api_request; }