In the Authorizenet SDK version 1.1.8 for PHP Is there a way to charge a card using a customer payment profile? - payment

I have been up and down through the SDK code and have the ability to add customer profiles and payment profiles for them but I can't see anywhere, where I can charge a card or create a subscription from a customer profile and customer payment profile. Does anyone have an answer for this for either the create subscription, or charge a card, using the PHP SDK. Please understand, giving me an interactive web example using AuthorizeNet's web API is not helpful here. The requirements are that it has to be done through the PHP SDK as we cannot have card user interaction past the point of the customer profile and customer payment profile creation.

First off need to define the normal credentials used for SDK requests
if (!defined("AUTHORIZENET_API_LOGIN_ID")) define("AUTHORIZENET_API_LOGIN_ID", {authorizenet_api_login_id};
if (!defined("AUTHORIZENET_TRANSACTION_KEY")) define("AUTHORIZENET_TRANSACTION_KEY", {authorizenet_transaction_key};
Then create the transaction and set the fields.
$transaction = new AuthorizeNetTransaction;
$transaction->amount = $amount;
$transaction->customerProfileId = $customerProfileId;
$transaction->customerPaymentProfileId = $customerPaymentProfileId;
// next line may be optional depending on your situation
$transaction->customerShippingAddressId = $customerShippingAddressId;
Then process the transaction
$request = new AuthorizeNetCIM;
$response = $request->createCustomerProfileTransaction("AuthCapture", $transaction);
if ($response->xml->messages->resultCode=="Ok") echo "It Was Approved"
;

Related

Creating a subscription using bank account number using stripe js in node js

I have created subscription by accespting credit/debit card number, exp month, exp year and cvc from front end angular app and creating
Customer
Product
Product Price
Payment Method
Subscription
In payment method i provide following details:
async function createPaymentMethod(data) {
let body = {
type: 'card',
card: {
number: data.card?.number,
exp_month: data.card?.exp_month,
exp_year: data.card?.exp_year,
cvc: data.card?.cvc
}
};
return await stripe.paymentMethods.create(body);
}
Now i want to create payment method but want to use customer's bank account number but i am unable to find a way to do it. I want to add "type: bank_account"
Note: I am using Strip JS and Node JS. All of this I want to do on server side i.e node js
Collecting Credit Card server-side is a bad idea, since you will expose yourself to the burden on PCI-Compliance. You would want to review Stripe's Integration Security Guide. Generally you would want to use client-side SDK to collect credit card information instead.
To the question of a bank account, it depends on which specific PaymentMethod you're gonna use (which country's bank transfer?) Ie. If you are talking about ACH in the US, you should follow the ACH Guide. Similarly it will collect bank account information client-side in exchange of a token, then passing it up to your back end.

How to extend a subscription after a customer submits payment

When I direct a user with an existing subscription to the Stripe payment page, Stripe automatically creates a new subscription at the time the customer submits payment.
What is the workflow that will allow me to tell Stripe that I want to extend the existing subscription and not create a new one?
I asked this question to Stripe support and this is the answer I got:
To answer your question, this will depend on your integration if you are using a third party platform to create this option, but with Stripe, this can only be done manually using the reference that we provided, this means that you have to extend the subscription without requiring a customer to make a payment first.
With regard to the third party platform, I don't understand why the API works differently for them and for me. Does this mean Stripe has a secret API and I MUST purchase a third party product to use the service effectively?
this means that you have to extend the subscription without requiring a customer to make a payment first.
This is the part that is giving me grief. This seems like an extraordinarily difficult workflow. At what point do I extend the subscription? What if the customer never pays? What triggers me to un-extend it? How can I reliably report to the customer the date their subscription ends? Extending a subscription seems like a fundamental, mundane task. Can it really be this difficult?
Edit code posted per requests:
SessionCreateOptions options = new SessionCreateOptions
{
PaymentMethodTypes = new List<string> { "card" },
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions { Price = order.PaymentProviderPlanID, Quantity = 1 }
},
Customer = order.CustomerID,
CustomerEmail = string.IsNullOrEmpty(order.CustomerID)? order.UserEmail : null,
Mode = "subscription",
SuccessUrl = hostURL + "/Subscription/CreateSubscription?session_id={CHECKOUT_SESSION_ID}",
CancelUrl = hostURL + "/SubActivationFailure",
};
Per clarifications to the question in the comments, do nothing and this will happen automatically. This is the default unless you explicitly set a subscription to cancel or for invoice to not be paid automatically.

How to prevent creating duplicate subscription in stripe when trial period is set on subscription

I am encoutering a problem with stripe. let me explain my working
scenario.my requirement is do not charge user for 14 days with card up front
1)user enter card details
2)sca popup appear
3)regardless of user complete the authentication or not a subscription is created in stripe because i set trial_end_date=>now()+14 days
4)user payment fails in some reason and attempt again, another subscription created
i am worried about the duplicate subscription as the stripe will attempt to pay after the 14 days for both of these subscription as it send a Stripe-hosted link for cardholders for both of these subscription
let me give a snapshot of what i have so far
$data['customer']='customerId';
$data['items']=[];
$data['items'][0]['plan']='stripe_plan_id'
$data['default_payment_method']='pm_xxxx'
$data['trial_end']= strtotime('+14 days');
$data['prorate']=true;
$data['tax_percent']=env('VAT_PERCENTAGE');
$data['expand']= ['latest_invoice.payment_intent', 'pending_setup_intent'];
try {
$subscription=\Stripe\Subscription::create($data);
}
catch(Exception $e) {
return response()->json(['success' => false,'message'=>$e->getMessage()]);
}
what i am missing? how to prevent the duplicate subscription scenario.please expain with the correct example which is i am missing.thanks in advance
I think the problem is in your payment flow, there is not a stripe api that explicitly detects duplicate subscription. You are after all allowed to assign more then 1 subscription per customer id. You can create idempotent keys, but that isn't for the same thing you're talking about, idempotent keys are for accidently hitting the submit button twice within the same timeframe.
The solution would be to attach a payment method to your stripe customer id before your subscription trial is over. For example if you are using stripe elements you would call
Node/JS Example below :
const result = await stripe.createPaymentMethod({
type: 'card',
card: card
})
then pass that result to your backend
const result = await stripe.paymentMethods.attach(paymentMethodId, {customerId})
You do not need to create a new subscription, as one has already been created for that user. Credit cards are assigned to customer Ids, and not to subscriptions. Stripe will do the rest.
You do also need to update the customer with the default payment method as follows :
const customer_update = await stripe.customers.update(stripeCustomerId,{invoice_settings: {default_payment_method:paymentMethodId}});
Now when you visit your dashboard you will see a default card assigned to your customer. Once the subscriptions falls out of the trail period, the default card will be charged.
So in this case there wont be a duplicate subscription created, as you are not calling stripe.subscriptions.create again.

Create Custom Stripe Connect Accounts

I have built a platform with buyers and sellers and now I would like to integrate payments.
I came across Stripe, it is quite easy and straight forward to use.
However, I found the documentation to be lacking since I want to implementation whereby the seller doesn't have to create a stripe account in order to get paid by the buyer.
What Stripe offers is a solution they call; stripe connect.
Stripe connect has three options; Standard, Express and Custom.
The solution that makes sense for my specific use case is the custom option.
From the documentation, they have this code snippet;
Stripe.api_key = 'STRIPE_SECRET_KEY'
account = Stripe::Account.create({
country: 'US',
type: 'custom',
requested_capabilities: ['card_payments', 'transfers'],
})
The above, they write, is used to create a custom account. Quite frankly, there isn't much to work with.
Has anyone developed something that I am trying to implement. Assistance in this regard would really be helpful.
I have implemented Express Stripe connect. This is an helper that I have written;
module ApplicationHelper
# Express Stripe url
def stripe_url
"https://dashboard.stripe.com/express/oauth/authorize?response_type=code&client_id=#{ENV["STRIPE_CONNECT_CLIENT_ID"]}&scope=read_write"
end
# Express Stripe Implementation
def stripe_connect_button
link_to stripe_url, class: "stripe-connect" do
content_tag :span, "Connect With Stripe"
end
end
end
I write <%= stripe_connect_button %> in the .erb file and it rendered properly. I am able to go through the entire process.
I would like to have a somewhat similar approach but for Custom Stripe Connect because with the above implementation, I had to create a stripe account as a seller.
I was able to test the custom stripe account creation using curl based on this
With curl it is like so;
curl https://api.stripe.com/v1/accounts \
-u STRIPE_SECRET_KEY: \
-d country=US \
-d type=custom \
-d "requested_capabilities[]"=card_payments \
-d "requested_capabilities[]"=transfers
The above returns json and I copy the id which an account_id. I use this id in another curl request;
curl https://api.stripe.com/v1/account_links \
-u STRIPE_SECRET_KEY: \
-d account= #{id} \
-d refresh_url="https://example.com/reauth" \
-d return_url="https://example.com/return" \
-d type=account_onboarding
This returns json that looks like so;
{
"object": "account_link",
"created": 1594988541,
"expires_at": 1594988841,
"url": "https://connect.stripe.com/setup/c/AUyum7LCw4cV"
}
Then I visit the url: https://connect.stripe.com/setup/c/AUyum7LCw4cV to do the on-boarding. I have successfully been able to create a stripe connect custom account.
However, I want to translate this flow to RubyOnRails.
So, my question is, how do I cause the below code snippet to initiate account creation when a Seller clicks a button (Connect To Stripe) ?
Stripe.api_key = STRIPE_SECRET_KEY
account = Stripe::Account.create({
country: 'US',
type: 'custom',
requested_capabilities: ['card_payments', 'transfers'],
})
In the Express Stripe Connect implementation, I had a url that I was passing to the button. With the above, I have no url to work with.
The code you share would create a Custom account on behalf of the seller in the API. This is only the first step before you can accept payments on their behalf and send funds to their bank account.
There are a lot of regulations around the flow of funds and the information you need to collect from the seller and you can't simply send $100 to a bank account in the US without completing those steps. Stripe covers in details all the information that needs to be collected depending on the type of business you are building and the countries you are going to operate in. You can read more about this here: https://stripe.com/docs/connect/required-verification-information
Collecting this information reliably can be fairly tricky early on for a project like yours. Similarly, rules and regulations evolve regularly, requiring you to collect more details for new users, backfill some missing information and do extra reporting.
This is why Stripe built their Connect Onboarding hosted page so that you can defer the collection of all information to them. You can read more about this here: https://stripe.com/connect/onboarding
Using Connect Onboarding is likely to be the best solution for your business as you can easily enable your sellers to provide the relevant information without having to own a Stripe account directly while you focus on the core parts of your own business.

How to implement Paypal subscription in a vue application?

I am working on a project which needs to deducts a fixed amount from a user's account to a business account on monthly basis. I am trying to create a Paypal button client side (vue) for accepting subscriptions on monthly basis. The users deduction information on monthly basis shall be stored in a database. The user shall also provided an option to cancel the subscription. Any help would be greatly appreciated.
Well i found out an answer after a little digging in the documentation provided at https://developer.paypal.com/docs/subscriptions/integrate and went through the steps they provided.
Steps
Create a product through their API by providing access_token in the headers.
After the product has been created, get product-Id from response and then create plan using the product_id in request body.
After the plan has been successfully created copy Plan_id and replace the id in smart subscription button.
paypal.Buttons({
createSubscription: function(data, actions) {
return actions.subscription.create({
'plan_id': 'P-your_plan_id'
});
onApprove: function(data, actions) {
alert('You have successfully created subscription ' + data.subscriptionID);
}
}

Resources