I am trying to integrate Paypal REST SDK where user is redirected to Paypal website for payment and returns after success(or failure). The documentation page says(in red box)
that "use of PayPal REST is restricted for credit cards"
On reading online discussions, somewhere it is mentioned that "direct credit cards" can't be accepted. Firstly, what is "direct credit card"? Then is it true that normal credit cards can pay via this SDK. Also, does direct credit card holders can pay via normal route too.
Note: I can't use Braintree Direct as advised in docs as it is still not available in India
The solution for the above question is called PayPal Guest Checkout.
Guest Checkout [hosted checkout solution on PayPal servers] is an option for buyers who don't have PayPal Account but can make a Payment using Credit Card which will redirect them to the PayPal website.
FLOW:
Checkout Page -> Checkout with PP(PayPal) -> No PP Account -> Guest Checkout -> Use Credit Card for Payment.
This is how Guest Checkout looks like.
Guest Checkout
Direct Credit Card[DCC]: It is seamless checkout using Credit Card on the website without being redirected to PayPal.
FLOW:
Checkout Page -> Select Pay using Credit Card -> Enter Card Details -> Submit
Here is how the DCC looks like.
Direct Credit Card Payment
Does this help?
Card Payment with Paypal
step-1 Add card Details
from paypalrestsdk import CreditCard
from paypalrestsdk import Payment
def card_payemnt(request):
paypalrestsdk.configure({
"mode": "sandbox", # sandbox or live
'client_id' :"",
'client_secret':"",
})
credit_card = CreditCard({
"type": "visa",
"number": "4024007185826731",
"expire_month": "12",
"expire_year": "2022",
"cvv2": "874",
"first_name": "Joe",
"last_name": "Shopper",
})
if credit_card.create():
print("CreditCard[%s] created successfully" % (credit_card.id ))
return HttpResponse('good')
else:
print("Error while creating CreditCard:")
print(credit_card.error)
step2 Complete Payment by using Card ID
def credit_card_payment(request):
paypalrestsdk.configure({
"mode": "sandbox", # sandbox or live
'client_id': "",
'client_secret': "",
})
payment = paypalrestsdk.Payment(
{
"intent": "sale",
"payer": {
"payment_method": "credit_card",
"funding_instruments": [
{
"credit_card_token": {
"credit_card_id": "CARD-7MH68586JW7132142LXWASJI",
}
}]
},
"transactions": [
{
"amount": {
"total": "6.70",
"currency": "USD"
},
"description": "Payment by vaulted credit card."
}]
}
)
if payment.create():
print(payment.id)
print("Payment created successfully")
else:
print(payment.error)
Related
I want to accept money through paypal. I need to send the user a link and get paid. The approval_link link is being created successfully. But it is not possible to pay using the link. I log in using this link, click pay, but I am redirected to return_url. I don't want this, I want the user not to be redirected anywhere. You just need to take the money from him and that's it. My project is not a website and I don't have any pages where you can redirect the client. Help to create a payment form without redirecting the client to other pages. I thank you in advance for the attention you paid to my problem and I apologize for my English.
I will repeat briefly: we need a payment form without redirecting to other pages. Just get the money. Please help to configure the parameters of paypalrestsdk.Payment()
import paypalrestsdk
api = paypalrestsdk.set_config(
mode="sandbox",
client_id="XXX",
client_secret="XXX")
token = api.get_access_token()
print(token)
payment = paypalrestsdk.Payment({
"intent": "sale",
"payer": {
"payment_method": "paypal"},
"redirect_urls": {
"return_url": "http://localhost:3000/process",
"cancel_url": "http://localhost:3000/cancel"
},
"transactions": [{
"item_list": {
"items": [{
"name": "item",
"sku": "item",
"price": "1.00",
"currency": "RUB",
"quantity": 1}]},
"amount": {
"total": "1.00",
"currency": "RUB"},
"description": "This is the payment transaction description."}]})
create = payment.create()
if create:
print("Payment created successfully")
else:
print(payment.error)
for link in payment.links:
if link.rel == "approval_url":
# Convert to str to avoid Google App Engine Unicode issue
# https://github.com/paypal/rest-api-sdk-python/pull/58
approval_url = str(link.href)
print("Redirect for approval: %s" % (approval_url))
I tried not to specify links for redirects. If they are not present, the payment is not created.
First of all you are using a deprecated v1/payments API and corresponding SDK. If you were going to implement a website checkout, you should use the current v2/checkout/orders API and its SDK instead; such an integration is documented here.
But your invoice use case is not a normal website checkout, as you've noted. Indeed there is a separate Invoicing API for it, see the invoicing integration guide.
There's no SDK for invoicing APIs--use direct HTTPS API calls to first obtain an oauth2 access token and then create your invoice.
I'm using Python and Braintree with the Drop-In. I try to not store a credit card in the vault, but the option seems to get ignored.
Here is my code:
result = gateway.transaction.sale({
"amount": order.total_amount,
"payment_method_nonce": request.data.get('nonce', 'none'),
"options": {
"submit_for_settlement": True,
"store_in_vault_on_success": False
},
})
Although the option is set to false after a successful payment (sandbox) and a page refresh the payment method is stored.
That's what you're looking for: https://github.com/braintree/braintree-web-drop-in/issues/470
In your Drop-In config on the client, you need the following config for not saving the credit card with a customer_id:
card: {
vault: {
vaultCard: false
},
},
How to save customer card info - Squareup API
Postman API available for create customer card which is not helping me to charge with card
How would i save card info also
"card_nonce": "YOUR_CARD_NONCE",
"billing_address": {
"address_line_1": "500 Electric Ave",
"address_line_2": "Suite 600",
"locality": "New York",
"administrative_district_level_1": "NY",
"postal_code": "10003",
"country": "US"
},
"cardholder_name": "Amelia Earhart",
"verification_token": "TOKEN"
}
> Link Used to create : https://{{host}}/v2/customers/{{customer_id}}/cards
Got My Solution In git repo, this repo help i am able to charge card directly
https://github.com/square/connect-api-examples/tree/master/templates/web-ui/payment-form/basic
I'm using the paypal-python-sdk.
Currently, I'm redirecting the user to paypal where they log in, click confirm, and are redirected back to my site. No issues there. However, I have no idea how to get the authorization id so I can capture the amount authorized (or smaller). According to the docs its supposed to exist under related_resources but the list is always empty.
Will authorizations completed by logging into paypal return an authorization id?
Clarification: I know I can execute the payment with the payment_id. However, executing the payment is out of the question because I must be able to capture less than authorized.
request = {
"intent": "authorize",
"redirect_urls": {
"return_url": PAYPAL_RETURN_URL,
"cancel_url": PAYPAL_CANCEL_URL
},
"payer": {
"payment_method": "paypal"
},
"transactions": [{
"amount": {
"total": str(self.order.total),
"currency": "USD"
},
"description": "Lorem lipsum"
}]
}
payment = Payment(request, api=self._connection())
I want to test it on the side of the functionality of the subscription payment gateway Braintree - for my application using Django (python).
Your code I have only one py file. (without front-end). When I want to create a subscription I get an error:
<ErrorResult 'Payment method token is invalid.' at 7f101d301390>
How can I get token payment method?
Here is all my code:
import braintree
braintree.Configuration.configure(braintree.Environment.Sandbox,
merchant_id="myMechrantId",
public_key="myPublicKey",
private_key="myPrivateKey")
client_token = braintree.ClientToken.generate()
client = braintree.Customer.create({
"first_name": 'Mike',
"last_name": "Smith",
"company": "Braintree",
"email": "jen#example.com",
"phone": "312.555.1234",
"fax": "614.555.5678",
"website": "www.example.com"
})
result = braintree.Subscription.create({
"payment_method_token": "the_token",
"plan_id": "Here is my plan ID"
})
I work at Braintree. Please get in touch with our support team if you have more questions.
In general, one of the main benefits of a service like Braintree is that you never have to handle credit card numbers, so you're better off following the Braintree recurring billing guide instead, which will better match a real integration with Braintree.
That said, if you do want to test it without a front-end, you can test it like this:
result = braintree.Customer.create({
"credit_card": {
"number": "4111111111111111",
"expiration_date": "12/16"
}
})
result = braintree.Subscription.create({
"payment_method_token": result.customer.credit_cards[0].token,
"plan_id": "my_plan_id"
})
It's late but I got stuck on this problem recently, this is the solution that helped me
customer_create_result = gateway.customer.create({
"first_name": user.first_name,
"last_name": user.middle_name + '' + user.last_name,
"payment_method_nonce": payment_method_nonce
})
subscription_create_result = gateway.subscription.create({
"payment_method_token":
customer_create_result.customer.payment_methods[0].token,
"plan_id": braintree_plan_id
})
where payment_method_nonce can be obtained from payload.nonce on payment button click and braintree_plan_id is the id for the plan you create in braintree control panel
here is the braintree reference that helped me
https://developer.paypal.com/braintree/docs/guides/customers#create-with-payment-method