Add a new credit card to paypal recurring payment profile - php

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 .

Related

Updating and Invoicing Stripe Subscription Quantity with Invoice description laravel cashier

Good Day,
I'm working on a project involving Laravel Cashier. I want to give user's the ability to update their subscription quantity and get charged immediately (which I have been able to achieve, using the code below)
$user = Auth::user()
$user->subscription('main')->incrementAndInvoice(10000);
As much as the above works as expected, the invoice returned doesn't include a description indicating the changes instead the invoice description is blank. But when I checked the Event Data on stripe the two descriptions are there [see below image]
The above images shows a user who was currently on a subscription plan with 5000 quantities but increased to 15000 quantities. Is there a way to include these descriptions in the invoice generated.
After i checked the incrementAndInvoice() method , it only accepts two parameter (1. count, 2. Plan) as seen below;
no option to include description like we have for the charge() method. Is there any workaround to this? Any ideas or pointers in the right direction would be really appreciated.
Thanks for your help in advance.
At the time being there is no implementation to include the description in incrementAndInvoice().
So we have to implement it and before we do that please checkout Update an invoice.
First change this line: $user->subscription('main')->incrementAndInvoice(10000); to $subscription = $user->subscription('main')->incrementAndInvoice(10000); (we are assigning it to $subscription variable)
then get the invoice as below:
$new_invoice = $user->invoices()->filter(function($invoice) use ($subscription) {
return $invoice->subscription === $subscription->stripe_id;
});
After updating the subscription quantity we will add the following:
$client = new \GuzzleHttp\Client();
$request = $client->post('https://api.stripe.com/v1/invoices/' . $invoice_id, [
'auth' => [$secret_key, null]
'json' => ['description' => 'your description']
]);
$response = json_decode($request->getBody());
Or the following:
$stripe = new \Stripe\StripeClient(
$secret_key
);
$stripe->invoices->update(
$invoice_id,
['description' => 'your description']
);
Please note that:
the $invoice_id is the id of the invoice.
the $secret_key is the API key.

How to add credit by default in WHMCS

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

Magento Credit card number mismatch with credit card type exception

I am using stripe credit card payment method for website on my magento store and developing a mobile application. I am developing the api's using native magento api. Problem occurred on create order api, everything till adding payment for stripe credit card works fine but when I hit the create order api it throws the exception.
"Credit card number mismatch with credit card type exception"
Below is api code, Please share your knowledge for this issue. Thanks in advance.
$proxy = new SoapClient($this->_client); //soap handle
$sessionId = $proxy->login($this->_apiuser, $this->_apikey);
$resultCustomerAddresses = $proxy->call($sessionId, "cart_customer.addresses", array($shoppingCartId, $arrAddresses));
if ($resultCustomerAddresses != TRUE)
{
return json_encode(array('status' => 0, 'result' => array(),'message' => 'Error in saving address'));
}
$resultShippingMethods = $proxy->call($sessionId, "cart_shipping.list", array($shoppingCartId));
$randShippingMethodIndex = rand(0, count($resultShippingMethods)-1 );
$shippingMethod = $resultShippingMethods[$randShippingMethodIndex]["code"];
$resultShippingMethod = $proxy->call($sessionId, "cart_shipping.method", array($shoppingCartId, $shipping_method));
//$resultTotalOrder = $proxy->call($sessionId,'cart.totals',array($shoppingCartId));
$paymentMethod = array(
"method" => $payment_method
);
$resultPaymentMethod = $proxy->call($sessionId, "cart_payment.method", array($shoppingCartId, $payment_method));
$licenseForOrderCreation = null;
$resultOrderCreation = $proxy->call($sessionId,"cart.order",array($shoppingCartId, null, $licenseForOrderCreation));
I had the same problem and successfully solved it, see this answer: https://stackoverflow.com/a/41948259/1052675
Basically, you supply the card information before you save the quote. It will validate the card against regex patterns and configured purchase limits and make sure you can use the payment method.
Then it will forget the payment information.
So before you tell it to submit the order, you need to supply the card info again.
My solution was a custom endpoint for simplicity on the front end app and it enabled me to keep the card info in memory to re-save between saving the quote and submitting the order.

Error: Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCard request

I use Payum stable version 0.13 and Zend framework v2 for make payments via AuthorizeNet.
My code for test:
$storage = $this->getServiceLocator()
->get('payum')
->getStorage('LowbiddoPayment\Entity\AgreementDetails');
$details = $storage->create();
$details['currency'] = 'USD';
$details['amount'] = 100;
$details['card_num'] = new SensitiveValue('4111111111111111');
$details['exp_date'] = new SensitiveValue('10/16');
$details['description'] = 'Test';
$storage->update($details);
$this->getServiceLocator()
->get('payum.security.token_factory')
->setUrlPlugin($this->url());
$doneUrl = $this->url()->fromRoute('payment_done', array('id' => $orderId), array('force_canonical' => true));
$captureToken = $this->getServiceLocator()
->get('payum.security.token_factory')
->createCaptureToken('authorize-net-aim', $details, $doneUrl);
I have this error
/vendor/payum/payum/src/Payum/AuthorizeNet/Aim/Action/CaptureAction.php:58
Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCard request.
How can I fix it?
Thanks!
PayumModule does not provide (yet) a built-in ObtainCreditCardAction. So there are two ways to go.
You can ask for credit card information yourself. Like create a form than render it. User fills it and submit. You get that info and pass it to Payum with the rest of information. Authorize.Net AIM asks for 'card_num', 'exp_date' fields.
The other way is to create a zend specific ObtainCreditCardAction and add it to Payment object using addAction method. Here's an example of ObtainCreditCardAction for Symfony: https://github.com/Payum/Payum/blob/master/src/Payum/Core/Bridge/Symfony/Action/ObtainCreditCardAction.php

How do I fill the "Transaction Details" key/value table inside the Transaction screen of Magento Admin?

I've created a custom payment gateway but now I need to handle post payment notifications (just like IPN) to append additional information for a given transaction.
I've tried a lot of different combinations including:
Mage::getModel('sales/order')->load('#id')
->getPayment()
->getTransaction('#id')
->setAdditionalInformation('foo', 'bar')
->save();
Which doesn't produce any error (I'm able to retrieve order/payment/transaction)
But save action seems to be inoperant. I also tried to save through the payment object without luck.
Found out by myself :P
$payment->getTransaction($id)
->setAdditionalInformation(
Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS,
$data
)->save();
If you´re trying to include information on the "authorize" stage of paymnet, here´s an useful snippet (please change variables to your own data!):
public function authorize(Varien_Object $payment, $amount) {
.....
$_data = array( 'Tranx' => $_transax, 'Auth' => $_autho ...);
$payment->setTransactionAdditionalInfo(
Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS,
$_data);
$payment->setTransactionId($_authid)->setIsTransactionClosed(0);
return $this
}
$transactin_detail = Mage::getModel('sales/order')->loadByIncrementId($order_id)->getPayment()->getTransaction($transId)->save();
echo '<pre>';
print_r($transactin_detail);

Categories