Paypal Billing Agreement Invalid Plan Id PHP - php

I have been trying to execute a subscription plan. I have hit a roadblock in the form of the billing agreement. I keep getting the following error when trying to create the agreement.
{"name":"VALIDATION_ERROR","details":[{"field":"plan","issue":"Invalid Fields passed in plan. Pass only a valid plan-id."}],"message":"Invalid request. See details.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR"}
I am unsure where the issue lies, trying to force the agreement's set plan to output the id itself also causes a JSON error and does nothing productive.
If you need more info feel free to ask.
$createdPlan = $startPlan->create($paypal);
$patch = new Patch();
$value = new PayPalModel('{
"state":"ACTIVE"
}');
$patch->setOp('replace')
->setPath('/')
->setValue($value);
$patchRequest = new PatchRequest();
$patchRequest->addPatch($patch);
$createdPlan->update($patchRequest, $paypal);
$plan = Plan::get($createdPlan->getId(), $paypal);
$agreement = new Agreement();
$agreement->setName($product . ' Agreement')
->setDescription('Recurring Payment')
->setStartDate(date(c, time()+4));
$agreement->setPlan($plan);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$agreement->setPayer($payer);
$agreement->create($paypal);

I was able to fix this by creating a new plan object and only setting the id to the actual plan like so.
$jsonplan = new Plan();
$jsonplan->setId($createdPlan->getId());
$agreement->setPlan($jsonplan);

$createdPlan is the plan variable that you need to pass in the $agreement class
$agreement->setPlan($createdPlan);

Related

How to pay multiple invoice in 1 payment QUICKBOOKS API

Good Day!
I am currently working on a QUICKBOOKS API payment and is using their DevKit https://github.com/consolibyte/quickbooks-php its working just fine, I can retrieve invoices and pay them individually. Now, I want to create a functionality that can pay multiple invoices in 1 payment. What I could think right now is doing a loop until all selected invoices gets paid individually but I guess its not the correct approach..
this is the code I got from the DevKit
$PaymentService = new QuickBooks_IPP_Service_Payment();
// Create payment object
$Payment = new QuickBooks_IPP_Object_Payment();
$Payment->setPaymentRefNum('WEB123');
$Payment->setTxnDate('2014-02-11');
$Payment->setTotalAmt(10);
// Create line for payment (this details what it's applied to)
$Line = new QuickBooks_IPP_Object_Line();
$Line->setAmount(10);
// The line has a LinkedTxn node which links to the actual invoice
$LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
$LinkedTxn->setTxnId('{-84}');
$LinkedTxn->setTxnType('Invoice');
$Line->setLinkedTxn($LinkedTxn);
$Payment->addLine($Line);
$Payment->setCustomerRef('{-67}');
// Send payment to QBO
if ($resp = $PaymentService->add($Context, $realm, $Payment))
{
print('Our new Payment ID is: [' . $resp . ']');
}
else
{
print($PaymentService->lastError());
}
If I put them inside a loop, I am sure they will all get paid and also it will create multiple payments as well.
Is there any other much better ways to do this? please help. Thanks!
Just do this stuff more than one time:
// The line has a LinkedTxn node which links to the actual invoice
$LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
$LinkedTxn->setTxnId('{-84}');
$LinkedTxn->setTxnType('Invoice');
$Line->setLinkedTxn($LinkedTxn);
$Payment->addLine($Line);
For example:
foreach ($invoices as $invoice_id)
{
// The line has a LinkedTxn node which links to the actual invoice
$LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
$LinkedTxn->setTxnId($invoice_id);
$LinkedTxn->setTxnType('Invoice');
$Line->setLinkedTxn($LinkedTxn);
$Payment->addLine($Line);
}
I made it work with this code
$c = 0;
foreach ($invoice_ids as $i) {
$Line = new QuickBooks_IPP_Object_Line();
$Line->setAmount($i_line_amount[$c]); //amount per line
$LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
$LinkedTxn->setTxnId($i);
$LinkedTxn->setTxnType('Invoice');
$Line->setLinkedTxn($LinkedTxn);
$Payment->addLine($Line);
$c++;
}

CyberSource SOAP Toolkit API Token Payment?

I would like to test a payment with already created token from the previous transaction, but can't really find a way to do that using SOAP Toolkit API.
I found this in their documentation:
Requesting an On-Demand Transaction
An on-demand transaction is a real-time transaction using the details stored in a customer profile. On-demand transactions that you can request are:
 Credit cards—authorization, sale (an authorization and capture), and credit.
 Electronic checks—debit and credit.
 PINless debits—debit.
To request an on-demand sale transaction:
Step 1 Set the ccAuthService_run service field to true.
Step 2 Set the ccCaptureService_run service field to true.
Step 3 Include the following fields in the request:
 merchantID
 merchantReferenceCode
 purchaseTotals_currency
 purchaseTotals_grandTotalAmount
 recurringSubscriptionInfo_subscriptionID
So I assumed that recurringSubscriptionInfo_subscriptionID is the token that I need to provide, and wrote this code:
$referenceCode = 'my_merchant_id';
$client = new CybsSoapClient();
$request = $client->createRequest($referenceCode);
// Build a sale request (combining an auth and capture).
$ccAuthService = new stdClass();
$ccAuthService->run = 'true';
$request->ccAuthService = $ccAuthService;
$ccCaptureService = new stdClass();
$ccCaptureService->run = 'true';
$request->ccCaptureService = $ccCaptureService;
$request->merchantID = 'my_merchant_id';
$request->merchantReferenceCode = uniqid();
$request->purchaseTotals_currency = 'USD';
$request->purchaseTotals_grandTotalAmount = '25';
$request->recurringSubscriptionInfo_subscriptionID = 'xxxxxxxx';
$reply = $client->runTransaction($request);
When I first run this code, the API complained that I didn't provide billing info, but I thought that's not necessary cause I provided the token for payment. After adding the billing info, it started complaining about missing credit card number, which doesn't make any sense, cause the whole point is to avoid sending those information and use payment token instead.
I believe you need to enable name-value-pairs in order to provide fields using _ for nesting (e.g: recurringSubscriptionInfo_subscriptionID), when I changed your code to use XML payloads it worked:
// ...
$ccAuthService = new stdClass();
$ccAuthService->run = 'true';
$request->ccAuthService = $ccAuthService;
$ccCaptureService = new stdClass();
$ccCaptureService->run = 'true';
$request->ccCaptureService = $ccCaptureService;
$request->merchantID = '<my merchant id>';
$request->merchantReferenceCode = uniqid();
$recurringSubscriptionInfo = new stdClass();
$recurringSubscriptionInfo->subscriptionID = '<my subscription token>';
$request->recurringSubscriptionInfo = $recurringSubscriptionInfo;
$purchaseTotals = new stdClass();
$purchaseTotals->currency = 'USD';
$purchaseTotals->grandTotalAmount = '100';
$request->purchaseTotals = $purchaseTotals;
// ...

Could not process Bank Of America debit or credit cards -> Card declined by issuer

We’ve just implemented Authorize.net on our new platform to replace our old one (braintree).
We have done some tests, from the charge credit card example that we adapted to our code.
It worked perfectly fine with Chase and Capital One debits card but didn’t work on any of bank of america debit and credit cards for some mysterious reasons. When looking on my profile I can read "Card declined by issuer”. I called the bank and they said the card wasn’t activated (When you receive a new card you need to activate it first). But all the card we’ve tried have been activated for long and we already processed payments online with (it also work on Braintree).
I went to my merchant service representative but they haven’t been able to help me. Am I doing something wrong? Did you hear about similar issues ? I’m concerned for other issues with banks when turning this thing live.
Here is my piece of code :
`
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName($this->ci->config->item('AUTHNETAPILOGINID'));
$merchantAuthentication->setTransactionKey($this->ci->config->item('AUTHNETKEY'));
$refId = 'ref' . time();
// Remove potential white spaces
$ccn = preg_replace('/\s+/', '', $ccn);
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber( intval( $ccn ) );
$creditCard->setExpirationDate( $exp );
$creditCard->setCardCode( $cvc );
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);
$order = new AnetAPI\OrderType();
$order->setDescription("Ticket");
// Create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount( $amount );
$transactionRequestType->setOrder( $order );
$transactionRequestType->setPayment($paymentOne);
$request = new AnetAPI\CreateTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId( $refId );
$request->setTransactionRequest($transactionRequestType);
$controller = new AnetController\CreateTransactionController($request);
$response_api = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
if ($response_api != null)
{ // more code }`
I was hoping you could help me debut if it’s coming from here. Should I add the postal code or address to make sure it’s not a security issue on their end ? Where could that come from ? I’m a little lost on this.
Thanks!

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.

paypal recurring payment with initial payment

Hello im using paypal express checkout with the merchant sdk.
I have implemented recurring payment using the integration manual, but the given example doesnt make an initial payment(charge the user right away).
My code for making the payment is:
Initializing the payment:
$cart = $this->cart->getCart();
$items = $cart['items'];
$itemTotal = 0;
foreach ($items as $k => $item) {
$product = $this->addItem($item);
$itemTotal += $product->Amount;
$this->paymentDetails->PaymentDetailsItem[$k] = $product;
}
$this->orderTotal->currencyID = 'USD';
$this->orderTotal->value = $this->cart->getCartAmount();
$this->paymentDetails->OrderTotal = $this->orderTotal;
$this->paymentDetails->PaymentAction = 'Sale';
$this->paymentDetails->InvoiceID = $invoice_id->{'$id'};
$setECReqDetails = new \PayPal\EBLBaseComponents\SetExpressCheckoutRequestDetailsType();
$setECReqDetails->PaymentDetails[0] = $this->paymentDetails;
$setECReqDetails->CancelURL = $this->cancelURL;
$setECReqDetails->ReturnURL = $this->returnURL;
$billingAgreementDetails = new \PayPal\EBLBaseComponents\BillingAgreementDetailsType('RecurringPayments');
$billingAgreementDetails->BillingAgreementDescription = 'recurringbilling';
$setECReqDetails->BillingAgreementDetails = array($billingAgreementDetails);
$setECReqType = new \PayPal\PayPalAPI\SetExpressCheckoutRequestType();
$setECReqType->Version = $this->version;
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReq = new \PayPal\PayPalAPI\SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
return $this->paypalService->SetExpressCheckout($setECReq);
And then on the return url i supplied i create the recurring payment with this code:
$profileDetails = new \PayPal\EBLBaseComponents\RecurringPaymentsProfileDetailsType();
$profileDetails->BillingStartDate = "2014-01-24T00:00:00:000Z";
$paymentBillingPeriod = new \PayPal\EBLBaseComponents\BillingPeriodDetailsType();
$paymentBillingPeriod->BillingFrequency = 10;
$paymentBillingPeriod->BillingPeriod = "Day";
$paymentBillingPeriod->Amount = new \PayPal\CoreComponentTypes\BasicAmountType("USD", "1.0");
$scheduleDetails = new \PayPal\EBLBaseComponents\ScheduleDetailsType();
$activationDetails = new \PayPal\EBLBaseComponents\ActivationDetailsType();
$activationDetails->InitialAmount = new \PayPal\CoreComponentTypes\BasicAmountType('USD', 49);
$activationDetails->FailedInitialAmountAction = 'ContinueOnFailure';
$scheduleDetails->Description = "recurringbilling";
$scheduleDetails->ActivationDetails = $activationDetails;
$scheduleDetails->PaymentPeriod = $paymentBillingPeriod;
$createRPProfileRequestDetails = new \PayPal\EBLBaseComponents\CreateRecurringPaymentsProfileRequestDetailsType();
$createRPProfileRequestDetails->Token = $token;
$createRPProfileRequestDetails->ScheduleDetails = $scheduleDetails;
$createRPProfileRequestDetails->RecurringPaymentsProfileDetails = $profileDetails;
$createRPProfileRequest = new \PayPal\PayPalAPI\CreateRecurringPaymentsProfileRequestType();
$createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetails;
$createRPProfileReq = new \PayPal\PayPalAPI\CreateRecurringPaymentsProfileReq();
$createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;
return $this->paypalService->CreateRecurringPaymentsProfile($createRPProfileReq);
}
In my sandbox account i can see that the recurring payment is created, but there is no initial payment.
My question is: How can i setup this recurring payment, so that an initial payment is made?
Hope i`ve explained good my problem. If you need more information comment.
EIDT: My question was how to create a recurring payment with initial payment. and i edited my code snippet. After some reading i saw that i missed to set it up with setting "ActivationDetailsType". I set it up and it works fine with one problem ... The payment profile is pending for 4-5 hours and then comes through. I read in forums and etc... that this was a sandbox issue but unfortunetly i cannot be sure that the payment will not be deleyd. In my case i need the payment to be approved right away. My new question is, when creating recurring payment profile, and the response for the account is ok(succes or what not) and the profile is pending can i count the payment as successful and be sure i`ll get the money for sure
Thank you for the time.
Regards,
Georgi
Quite late but I'm having similar concerns.
My new question is, when creating recurring payment profile, and the response for the account is ok(succes or what not) and the profile is pending can i count the payment as successful and be sure i`ll get the money for sure?
I'm currently working on it but I wouldn't count the pay until PayPal reflects the payment. I would utilize the IPN to trigger actions that should be made when the payment has come through. As for the 4-5 hour processing by PayPal (though sources from the web say production should not have the same delay), I'll just be sure to notify the buyer that his/her payment is still being processed by PayPal.

Categories