How to add credit by default in WHMCS - php

How can I add default credit in WHMCS?
I mean when a user signup with WHMCS, they will receive some predefined credit balance in their account (credits can be used to purchase products)
I did search but didn't get any result.

You could use WHMCS hook system together with the API.
I haven't tested this code, but it should work more or less out of the box.
Create a file in includes/hooks/
add_hook('ClientAreaRegister', 1, function($vars) {
$command = "addcredit";
$adminuser = "admin";
$values["clientid"] = $vars['userid];
$values["description"] = "Adding credits via ClientAreaRegister hook";
$values["amount"] = "40.00";
$results = localAPI($command,$values,$adminuser);
});
Make sure you have a user "admin" or create a new user and change above code to match.
References:
https://developers.whmcs.com/hooks-reference/client-area-interface/#clientarearegister
http://docs.whmcs.com/API:Add_Credit

Related

Add a new credit card to paypal recurring payment profile

I have a feature in my website that a user can change/update/add a credit card in his/her Paypal recurring payment profile. But while updating the profile nothing happens. Please help.
Code is as below:
require_once("paypal_pro.inc.php");
$paypalPro = new paypal_pro('xxxxxxxxxxxxxxxxxxxxx.gmail.com', 'xxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', '', '', FALSE, FALSE );
$paymentAction = urlencode("Sale");
$methodToCall = 'UpdateRecurringPaymentsProfile';
$padDateMonth = str_pad(4, 2, '0', STR_PAD_LEFT);
$expDateYear =urlencode( 2018);
$expDate = $padDateMonth.$expDateYear;
$nvpstr='&PAYMENTACTION='.$paymentAction.'&METHOD=UpdateRecurringPaymentsProfile&PROFILEID=I-NGYJW5L1TLNV&CREDITCARDTYPE=VISA&ACCT=4111111111111111&CVV2=123&EXPDATE='.$expDate;
$resArray = $paypalPro->hash_call($methodToCall,$nvpstr);
echo '<pre>';
print_r($resArray);
I am trying this with a sandbox account.
First of all you need to tell where are you writing this code. Don't mind but your code looks like not as it should be:
1- Which version are you using (Yii1 | Yii2)? I guess Yii1
if you are using yii1 and you want to perform this stuff under profile update Action.
so lets consider "profile/update" Action. so there will be some thing like below under "ProfileController".
public function actionUpdate(){
//some thing will be placed here....
}
There are 2 ways to do it. one just do it along with the controller or user Hooks (recommended) so it will be under "Model afterSave" hook. some thing like that. you can use any extension / component / widget.
Paypal Extension can tell you how you can do it .

PayPal Adaptive Payments - Product Name

I am using paypal adaptive payments for my website. I have many sellers and different products. when I am as a user try to buy any product from my website then I can't see product name in Paypal form summary instead there is the name and surname of the seller.
Let me know please which parameter is being used to Pass product name ..
Here is the screenshot
With Adaptive Payments you can't send itemized details in the Pay request itself. Instead, you have to call Pay like usual, but then follow that up with a call to SetPaymentOptions. With that you'll pass in the PayKey you get back from the Pay request, and then you can setup all the additional details like itemized info that SetPaymentsOptions provides.
Then you would redirect to PayPal after that, and it should show you what you're after.
With Adaptive Payments, the item details you set with SetPaymentOptions are only displayed to the customer via Embedded flow.
The Embedded flow uses either a lightbox or a minibrowser for the checkout pages.
Here’s a technical instruction on how to implement the embedded flow in your front-end page, https://developer.paypal.com/docs/classic/adaptive-payments/ht_ap-embeddedPayment-curl-etc/
I am having the same issue. It looks like it works only in an Embedded Payment Flow.
Embedded Payment Flow Using Adaptive Payments
$receiverOptions = new PayPal\Types\AP\ReceiverOptions();
$setPaymentOptionsRequest->receiverOptions[] = $receiverOptions;
$receiverOptions->description = 'Description';
$invoiceItems = array();
$item = new PayPal\Types\AP\InvoiceItem();
$item->name = 'Item Name';
$item->price = 10;
$item->itemPrice = 10;
$item->itemCount = 1;
$invoiceItems[] = $item;
$receiverOptions->invoiceData = new PayPal\Types\AP\InvoiceData();
$receiverOptions->invoiceData->item = $invoiceItems;
$receiverId = new PayPal\Types\AP\ReceiverIdentifier();
$receiverId->email = 'email#domain.com';//Change it
$receiverOptions->receiver = $receiverId;
$setPaymentOptionsRequest->payKey = $_POST['payKey'];
$servicePaymentOptions = new PayPal\Service\AdaptivePaymentsService($config);
try {
/* wrap API method calls on the service object with a try catch */
$responsePaymentOptions = $servicePaymentOptions->SetPaymentOptions($setPaymentOptionsRequest);
print_r($responsePaymentOptions); die;
} catch(Exception $ex) {
//error
}
if (isset($responsePaymentOptions) && $responsePaymentOptions->responseEnvelope->ack == "Success")
{
//Success
}

Recurlyv3 API doesn't find any data associated with valid token id

This is the essential bit of PHP:
// Add subscription
$subscription = new Recurly_Subscription();
$subscription->plan_code = $planCode;
$subscription->currency = 'USD';
$subscription->quantity = 1;
if ($couponCode != "") { $subscription->coupon_code = $couponCode; }
$subscription->account = new Recurly_Account();
$subscription->account->account_code = $customerID;
$subscription->billing_info = new Recurly_BillingInfo();
$subscription->account->billing_info->token_id = $token;
$subscription->create();
When this code runs, $token has the tokenID created by an earlier call to recurly.token (...) with the billing info.
The account already exists on Recurly -- the account ID, first and last names, but no billing info. This is because we allow people to signup for a complimentary service before subscribing. So I want to create the subscription on the extant account. Initially, following the code examples, the create() call was subscription->account->create(). But that failed because the account existed already.
This sounds like an issue with the old PHP library, which did not support tokenization of billing information. An upgrade to the PHP client library should fix this issue.

Magento - Programatically retrieve and set admin users status

For a custom extension I'm building I need to be able to set and retrieve the status of an administrator user (not a customer) in Magento. I imagine you could achieve this like so;
$id; // ID of user stored here
$user = $mage->getadminuser($id); // store the user as an object or array in a variable with ID
$user->getStatus(); // return either true or false?
$user->setStatus(active or not active); // activate or deactivate the user
If anyone could provide me with the code to do this or documentation where I can find this easily?
Thanks!
$id = 5;
$admin = Mage::getModel('admin/user')->load($id);
if ($admin->getId()){
$admin->setIsActive(1);//or 0
$admin->save();
}

How to get customer profile using CIM in Authorize.Net?

I am working of CIM (Customer information manager) and i have created customer profile using CIM function. But i want to get customer profile using customer id instead of customer profile id.
$cim = new AuthnetCIM('***MASKED***', '***MASKED***', AuthnetCIM::USE_DEVELOPMENT_SERVER);
$cim->setParameter('email', 'fakeemail#example.com');
$cim->setParameter('description', 'Profile for Joe Smith'); // Optional
$cim->setParameter('merchantCustomerId', '7789812');
//create profile function
$ss=$cim->createCustomerProfile();
//and get profile by..
$profile_id = $cim->getProfileID();
You can't. You can only get the profile using the profile ID. This means you'll want to store that ID in your database and associate it with the customer's record so whenever you need to get their profile you know what their Profile ID is.
Actually it is possible if you must, however I would still recommend storing it if possible, but this alternative might be of help.
Authorize.Net defines a unique customer profile by the composite key (Merchant Customer Id, Email, and Description), thus you must ensure this is unique. The CreateCustomerProfile(..) API method will enforce uniqueness and return an error if you attempt to create the same composite key again, as it should. However, the message in this response will contain the conflicting customer profile id, and since your composite key is unique, and Authorize.Net enforces uniqueness of this composite key, then this must be the Authorize.Net customer profile id of your customer.
Code sample in C#
private long customerProfileId = 0;
var customerProfile = new AuthorizeNet.CustomerProfileType()
{
merchantCustomerId = "123456789",
email = "user#domain.com",
description = "John Smith",
};
var cpResponse = authorize.CreateCustomerProfile(merchantAuthentication, customerProfile, ValidationModeEnum.none);
if (cpResponse.resultCode == MessageTypeEnum.Ok)
{
customerProfileId = cpResponse.customerProfileId;
}
else
{
var regex = new Regex("^A duplicate record with ID (?<profileId>[0-9]+) already exists.$", RegexOptions.ExplicitCapture);
Match match = regex.Match(cpResponse.messages[0].text);
if (match.Success)
customerProfileId = long.Parse(match.Groups["profileId"].Value);
else
//Raise error.
}

Categories