Braintree testing, can't get braintree to reject card - php

It must be something simple but I'm pulling my hair out. When I call this
$data = [
'amount' => '50.00',
'paymentMethodNonce' => 'fake-processor-declined-mastercard-nonce',
'options' => [
'submitForSettlement' => true
]
];
$result = Braintree_Transaction::sale($data);
I get back "success" from Braintree. How do I get the card declined?

So it turns out that on the Braintree_Transaction::sale method using the fake-nonce isn't the way you do it. You do it with the amount. You match the amount to the error code you want to produce. So an amount of 2001.00 will get a response of "Insufficient Funds". A list of error codes can be found here

Related

Amount must be greater than zero, PayPal/Braintree payment

I have an app that sells events, some events have zero-dollar price. Thus, I receive this message from PayPal:
Amount must be greater than zero
However, if I remove the need to make a payment, one user can order all the tickets for an event. So, what's the way to make users go through the payment process without making a charge.
Bear in mind, it'd be great to make as little change to the process in terms of generating a Nonce from frontend and sending it to backend to make the charge it.
I'm using this payment scenario.
This is the function that returns the error message:
public function chargeNonce($nonce) {
$gateway = $this->createPayPalGateway();
$amount = $this->payment_params['number_of_tickets'] * $this->payment_params['event_price'];
$result = $gateway->transaction()->sale([
'amount' => $amount,
'paymentMethodNonce' => $nonce,
'options' => [
'submitForSettlement' => True,
'paypal' => [
'description' => "Billing Notification",// For email receipt
],
],
]);
dd($result);
return $result;
}

How to get the ID out of Braintree's JSON response?

I'm trying to integrate PayPal Express Checkout using Braintree SDK.
I can so far charge the Nonce returned from the client and I receive this response. However, I need to take the ID out in order to save it in a table.
My question is how do I parse the id??
Successful {#315
+success: true
-_returnObjectNames: array:1 [
0 => "transaction"
]
#_attributes: []
+"transaction": Transaction {#324
#_attributes: array:63 [
"id" => "xxx"// How do I parse this out?
"status" => "settling"
"type" => "sale"
"currencyIsoCode" => "USD"
"amount" => "6.00"
The variable that holds this JSON is $success. Thus, I tried several things like:
$success->transaction->id
$success->id
If I do $success->success I get true and If I do $success->transaction I get the Transaction object.
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact
support.
If running $success->successreturns True and $success->transaction returns the Transaction object, then you should be able to query the transaction ID using $success->transaction->id, we also demonstrate this in our developer documentation.
$result = $gateway->transaction()->sale([
'amount' => '10.00',
'paymentMethodNonce' => nonceFromTheClient,
'options' => [
'submitForSettlement' => True
]
]);
if ($result->success) {
// See $result->transaction for details
} else {
// Handle errors
}

Trouble downgrading/upgrading subscription on Stripe with PHP

I'm using Stripe for my recurring payment for my SAAS.
The problem I'm facing today is : I would like to offer to my client the choice to upgrade or downgrade their subscription to my service.
So the code I have actually is the following (according to the doc here):
\Stripe\Subscription::update($subscriptionID, [
'items' => [
'id' => $itemID,
'plan' => $planId
]
]);
The $subscriptionID, $itemID and $planId return my the right value I need but no update on the Stripe side.
I have just this error:
{
"error": {
"type": "invalid_request_error",
"message": "Invalid array",
"param": "items"
}
}
Any help on his please ?
Thanks.
You just need to cover items in one more array level, like so:
\Stripe\Subscription::update($subscriptionID, [
'items' => [
[
'id' => $itemID,
'plan' => $planId
]
]
]);
It was working using this code:
$customer = \Stripe\Customer::retrieve($CustomerId);
$subscription = $customer->subscriptions->retrieve($subscriptionID);
$customer->updateSubscription(['plan' => $planId]);
$customer->save();
Strange that the Stripe API do not talk about this solution.

WePay API response error "payment method does not exist or does not belong to app"

i was having a problem with Wepay API. My codes are correct but it keeps on returning an error saying "payment method does not exist or does not belong to app". I already configured the permission to allow tokenized credit cards. But still. Any feedback is greatly appreciated. Thanks!
Here is my code
require_once('public/payment/wepay/wepay.php');
$user = API::get_client(['fldClientEmail' => $email])->first();
// change to useProduction for live environments
\Wepay::useStaging(WEPAY_CLIENT_ID, WEPAY_CLIENT_SECRET);
$wepay = new \WePay($user->fldClientWepayTokenAccess);
// $wepay = new \WePay(WEPAY_ACCESS_TOKEN);
// dd($email);die;
// dd($user->fldClientWepayAccountID);die;
// charge the credit card
$response = $wepay->request('checkout/create', [
'account_id' => $user->fldClientWepayAccountID,
'amount' => number_format(Input::get('amount_tipped'),2),
'currency' => 'USD',
'short_description' => 'A short description',
'type' => 'goods',
'payment_method' => array(
'type' => 'credit_card',
'credit_card' => array(
'id' => Input::get('cc_id')
)
)
]);
// display the response
return $response;
Make sure that when you follow the tutorial from their docs, you replace all of the credentials from the examples. I was using their Javascript library for the tokenization of the credit card with the client_id they provided.
response = WePay.credit_card.create({
"client_id": YOUR.CLIENT.ID.HERE,
"user_name": valueById('name'),
"email": valueById('email'),
"cc_number": valueById('cc-number'),
"cvv": valueById('cc-cvv'),
"expiration_month": valueById('cc-month'),
"expiration_year": valueById('cc-year'),
"address": {
"postal_code": valueById('postal_code')
}
If you don't provide your own, is like you were creating those credit cards for another application that's not yours.
If this didn't do the trick, check this article, hopefully it does:
https://support.wepay.com/hc/en-us/articles/203609273-WePay-API-Error-Codes

Braintree API in PHP success and currency issue

My braintree integration is going well - there's just two minor issues.
Firstly what is the option name to pass through and specify a currency code e.g.:
$options = [
"amount" => "10.00"
"creditCard" => [
"number" => "",
"cvv" => "",
"expirationMonth" => "",
"expirationYear" => ""
],
"currencyCode" => "AUD" // This is what im after?
];
Secondly, when I run the code below I get this: "Undefined property: Braintree_Result_Successful::$_attributes" when running the check on success?
$result = Braintree_Transaction::sale($this->collect_data());
if($result->success) { // do something }
I work at Braintree. If you have more questions, please feel free to get in touch with our support team.
To use a different currency, you specify a different merchant account:
$result = Braintree_Transaction::sale(array(
'amount' => '100.00',
'merchantAccountId' => 'gbp_merchant_account',
'creditCard' => array(
'number' => '5105105105105100',
'expirationDate' => '05/12'
)
));
Contact Braintree to get the additional merchant accounts set up.
For your second question, I've not seen that error before. Your best bet is to contact Braintree support so they can help you with the problem.

Categories