Braintree: test nonces are resulting in Payment Method Nonce is Invalid - javascript

I am in the process of using the sandbox to test creating a new recurring billing subscription using a fake nonce but I keep getting an error indicating the
payment nonce is invalid, here is the object I am sending to the gateway.subscription.create method:
{
paymentMethodNonce: 'fake-valid-nonce',
planId: 'ip19',
price: 2.5,
options: { startImmediately: true }
}
This is the error I am receiving when I make me call to gateway.subscription.create:
[
ValidationError {
attribute: 'payment_method_nonce',
code: '91925',
message: 'Payment method nonce is invalid.'
}
]
I am using the fake nonces listed in this article, https://developer.paypal.com/braintree/docs/reference/general/testing/node#nonce-fake-valid-nonce
I am passing the sandbox credentials when I make my initial connection but it seems like it is not honoring the fake nonce.

None of them have ever worked? They should work at least once. Otherwise, if you have a payment method in your vault, do something like braintree.PaymentMethodNonce.create('token').payment_method_nonce.nonce to generate a new nonce for server-side testing.

Payment method nonces can only be used in certain specific conditions. Fake nonces do not support these specific use cases. You need to use a payment method token to create a subscription or use a generated payment method nonce from the specific client workflows mentioned in the API reference.

Related

Stripe 3dSecure createSource set custom parameter in redirect url

I'm unable to set a custom parameter in 3dSecure create source function, is someone know? I have tried some methods but it overrides my URL parameters.
When I added redirect url something: return_url: "www.example.com?orderid=10", after 3dSecure authorization it redirect me at www.example.com?client_secret=xyz&livemode=false&source=sdf
I can't get my orderid variable when it returns back on my site as I need to update the order.
Seriously very poor implementation of 3dSecure by Stripe. They mentioned in their docs that you can set custom GET params but not given an example.
You may include any other GET parameters you may need when specifying redirect
stripe.createSource({
type: 'three_d_secure',
amount: totalAmount,
currency: "eur",
three_d_secure: {
card: result.source.id
},
redirect: {
return_url: "www.example.com?orderid=10",
}
}).then(function(result2) {
});
I whipped up a working example from something I had written up previously. You can find it here:
https://jsfiddle.net/78y1brho/
Basically, it uses Stripe.js/v2 to make a token from the input box, then a card source from the resulting token. You can ignore that though. The part that matters is the code in the populateCard()-function on Line #33.
That code is where you setup the return variable. When I did this, it worked fine and returned me to:
https://test.test.test/myresponse?client_secret=src_client_secret_xxx&livemode=false&source=src_xxx&this=atest
The notable part being the this=atest at the end. I think maybe it's just that you're missing a protocol (https://) in your url that it's trimming everything. Maybe try including that?

Using Negative Testing via Paypal Express Checkout client-side JS button implementation

I'm currently working on a PayPal Express checkout integration using the Client-side JS approach for taking payments. I'm looking to utilise their "Negative Testing" feature to try to simulate potential errors and provide appropriate responses to the customer.
Just a reference to the relevant doc page here for reference
It seems to enable negative testing you need to pass an extra header along with the the payment request specifying the particular error you would like to trigger for that payment.
This is my current JS for setting up the transaction:
<script>
//We need to convert our generated json string into a bonified javascript object
var paypal_transaction = JSON.parse(JSON.stringify(<?php echo $paypal_json; ?>));
paypal.Button.render({
env: 'sandbox', // 'production'/'sandbox',
commit: true, // Show a 'Pay Now' button - Allows us to capture the payment right away
client: {
sandbox: 'Ab_hPp7h70DoFKChLMSynNxacQQbGcb_tP1cDbzW9jC6a0rYIZH0CkEYYfkw6csvmlyTmfLnagelqB85',
production:''
},
//How we want the button to look
style: {
size: 'responsive',
color: 'gold',
shape: 'rect',
label: 'pay'
},
headers: {
'{"mock_application_codes":"INSTRUMENT_DECLINED"}'
}
payment: function(data,actions) {
return actions.payment.create({
//Pass our created transaction to paypal.
payment:paypal_transaction,
/**
* We have to set the following fields to prevent the client from
* changing their delivery address when they're at PayPal
*/
experience: {
input_fields: {
no_shipping: 0,
address_override:1
},
}
});
},
onAuthorize: function(data, actions) {
/**
* [description]
* #param payment - The authorised transaction returned from paypal
* #return redirect - We redirect the cutomer to our confirmation page as soon as we return from PayPal as we're confident we have the correct
*/
return actions.payment.execute().then(function(payment) {
actions.redirect();
});
},
onError: function(err) {
console.log(err);
// Show an error page here, when an error occurs
},
onCancel: function(data, actions) {
return actions.redirect();
// Show a cancel page or return to cart
}
}, '#paypal-button');
Essentially my question is where do I specify the mock application codes like this in the above implementation.
In the docs they give an example cURL request with the below as the extra header that needs to be passed:
"PayPal-Mock-Response:{\"mock_application_codes\":\"INSTRUMENT_DECLINED\"}"
I just don't know how to do this via the JS approach. Can negative testing only be used with a server side implementation?
Hope that's all clear enough!
Had similar issue myself, and the official answer I got was that it is not available:
"I understand this is a frustrating situation. Unfortunately we do not
have any way to offer negative testing for client side integrations.
It may possible for you to do so using Postman, however, we do not
have documentation to offer."
This is really sad though, other payment providers have fixed card numbers for certain error scenarios for example, or have special payment value based codes. PayPal only has that for the Payflow integration, and the request header based mocking stuff is also only possible if you are directly calling their REST APIs.
PayPal is really lame in these aspects, as even if you are mocking behavior with server integration (not that hard, for this at least they have proper code examples), this mocking is explicit and you control the error. If it would be implicit, and originate from an actually validated but invalid card for example, it would be more realistic.

Meteor.js - Fetch/Get Enrollment token (from Accounts.sendEnrollmentEmail)

I can't figure out how to get the enrollment token from the Accounts.sendEnrollmentEmail function.
I know this function sends a direct mail towards the user which in the end looks something like this:
http://localhost:3000/#/enroll-account/FCXzBbqHInZgBlLaOpu8Iv11jP9DJEG-e1auAHDsh6S
However, I would need to somehow get only to the token part FCXzBbqHInZgBlLaOpu8Iv11jP9DJEG-e1auAHDsh6S as I want to send enrollment mail trough a different service (e.g Postmark)
How to do this?
The Accounts.sendEnrollmentEmail(userId, email) function generates a random token and saves it in the user's services.password.reset.token field.
The code that generates the token is:
var token = Random.secret();
var when = new Date();
var tokenRecord = {
token: token,
email: email,
when: when
};
Meteor.users.update(userId, {$set: {
"services.password.reset": tokenRecord
}});
(You can view the function's source code here).
It then sends an email to the user using the Email package. If you want to use a different service to send the email, you basically have 2 options:
Use the same convention yourself (i.e, create the same record and use your own email service in your own function).
Use the existing function, allow the mail delivery to fail silently and then query the user's document for the token and send the email yourself.
Neither is a particularly good option, but both will work for the time being. I wish they had refactored this part into its own function.
Note that the accounts packages are expected to undergo some changes towards the release of the next Meteor versions.
BTW, this function is very similar to Accounts.sendResetPasswordEmail, which you may also wish to override or create your own version.

how to create transaction without plan in braintree js+python?(whiteout subscription)

I am using braintree payment gateway in my application.
i am able to create the transactions with selecting the plan, but what i needed is to create the transaction without selecting any plan. One time payment.
my code
create_sub = braintree.Subscription.create({
"payment_method_token": the_token,
"plan_id": PLAN_ID
})
here subscription is created.
payment_method_result = braintree.PaymentMethod.create({
"customer_id": merchant_customer_id,
"payment_method_nonce": nonce,
"options": {
"make_default": True
}
})
here payment_method is got created
here what i want is to create transaction directly without subscribing.
and save all transaction related data to transaction model.
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
You can create a one-time transaction with Braintree's Python API library using the following call:
result = braintree.Transaction.sale({
"amount": "10.00",
"payment_method_token": the_token,
"options": {
"submit_for_settlement": True
}
})
This creates a single transaction with no affiliation to any plan. In place of the "payment_method_token", you may also use "payment_method_nonce", passing in the nonce received from your client. You can find the full list of available parameters in Braintree's API Documentation.

WebAPI using BreezeJS throws an error as soon as I use $skip

I have a working WebAPI (v2) which utilizes the awesome BreezeJS product. I am attempting to add paging capabilities, but as soon as I include $skip in the URL as a parameter, the WebAPI generates this error:
{
$id: "1",
$type: "System.Web.Http.HttpError, System.Web.Http",
Message: "An error has occurred."
}
Debugging the API does not give me any additional information, since it doesn't crash.
The parameters I'm passing are: http://www.example.com/api/Test/Designs?$skip=5&$top=5&$inlinecount=allpages&
If I call it without the $skip parameter, it works fine. The other "$" params seem to work just fine, as I can call:
http://www.example.com/api/Test/Designs?$top=3
and it works as expected.
I have verified that I'm not using any BreezeQueryable attributes or anything, so $skip should be allowed.
Additional setup info if it helps:
SQL Server Express v2012
Breeze on the server side is v1.5.0.0
Entity Framework v6
Microsoft.Data.OData is v5.6
Is there something else I need to have enabled in order to utilize paging? Or is there a way I can find the true cause of this error? I can provide a working URL if requested.
Thank you.
A sort is required to use skip:
From the breeze docs:
// Skip the first 10 Products and return the rest
// Note that the '.orderBy' clause is necessary to use '.skip'
// This is required by many server-side data service implementations
var query3 = EntityQuery.from('Products')
.orderBy('ProductName')
.skip(10);

Categories