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
}
Related
I'm new to paypal and sandbox, however the algorithm works fine with my on the localhost,
whereas it fails to complete the transaction on remote, I'm using php laravel
the algorithm on my paypal controller :
$request = new OrdersCreateRequest();
$request->prefer('return=representation');
$request->body = [
"intent" => "CAPTURE",
"purchase_units" => [[
"reference_id" => rand(000000,999999),
"amount" => [
"value" => number_format($amount, 2, '.', ''),
"currency_code" => \App\Models\Currency::findOrFail(get_setting('system_default_currency'))->code
]
]],
"application_context" => [
"cancel_url" => url('paypal/payment/cancel'),
"return_url" => url('paypal/payment/done')
]
];
try {
//ddd($request);
// Call API with your client and get a response for your call
$response = $client->execute($request);
// ddd($response);
// If call returns body in response, you can get the deserialized version from the result attribute of the response
return Redirect::to($response->result->links[1]->href);
}catch (HttpException $ex) {
}
When I dump the response it's as :
PayPalHttp\HttpResponse {#2005 ▼
+statusCode: 201
+result: {#2012 ▼
+"id": "29F719283B401012X"
+"intent": "CAPTURE"
+"status": "CREATED"
+"purchase_units": array:1 [▼
0 => {#1944 ▼
+"reference_id": "481922"
+"amount": {#1948 ▼
+"currency_code": "USD"
+"value": "150.00"
}
+"payee": {#1975 ▼
+"email_address": "sb-adxtx19866369#business.example.com"
+"merchant_id": "MUJ4QB7EWSWDJ"
}
}
]
+"create_time": "2022-08-30T10:04:38Z"
+"links": array:4 [▼
0 => {#1949 ▼
+"href": "https://api.sandbox.paypal.com/v2/checkout/orders/29F719283B401012X"
+"rel": "self"
+"method": "GET"
}
1 => {#2017 ▼
+"href": "https://www.sandbox.paypal.com/checkoutnow?token=29F719283B401012X"
+"rel": "approve"
+"method": "GET"
}
2 => {#2010 ▼
+"href": "https://api.sandbox.paypal.com/v2/checkout/orders/29F719283B401012X"
+"rel": "update"
+"method": "PATCH"
}
3 => {#2009 ▼
+"href": "https://api.sandbox.paypal.com/v2/checkout/orders/29F719283B401012X /capture"
+"rel": "capture"
+"method": "POST"
}
]
}
}
and The Exception i get :
PayPalHttp\HttpException
{"name":"UNPROCESSABLE_ENTITY","details": [{"issue":"COMPLIANCE_VIOLATION","description":"Transaction cannot be processed due to a possible compliance violation. To get more information about the transaction, call Customer Support."}],"message":"The requested action could not be performed, semantically incorrect, or failed business validation.","debug_id":"a548bb80c1863","links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-COMPLIANCE_VIOLATION","rel":"information_link","method":"GET"}]}
I've tried multiple ways to resolve it like :
1- Changing the sandbox account region from EGY to US.
2- Changing the entire paypal account.
I would appreciate a little assistance here.
Thanks in advance.
COMPLIANCE_VIOLATION
For sandbox testing: the receiving business account should not be from one of the countries listed here. So, it should work if you try again with e.g. a US receiver account (payer/sending account does not matter)
In the live environment: this answer has more details on the set up needed to receive payments in one of those countries with auto withdrawal to a card or bank.
After a long debugging, the thing turn out to be after the payments. nothing wrong with paypal.
I debugged untill I found the payment status "completed"
After the payment, I update my DB records.
in laravel I used findOrFail($id) method which turns out to be the problem
It fails to find the record, I don't know why however this terminates the logic.
thank you guys.
As per the stripe documentation here we read all the information and know the ideas about the SCA. But I am not getting any related API documentation. So, I am confusing how to implement in our existing PHP code and what are the parameters we will add. Please find below my example of code:
\Stripe\Stripe::setApiKey(API_KEY_HERE);
$customer = \Stripe\Token::create(
array("card" => array(
"name" => $arg['name'],
"number" => $arg['number'],
"exp_month" => $arg['exp_month'],
"exp_year" => $arg['exp_year'],
"cvc" => $arg['cvc']
))
);
/* some other code here */
$charge = \Stripe\Charge::create(
array(
"amount" => $arg['amount'],
"currency" => "usd",
"description" => "Subscription Charge",
"customer" => $customer->id
)
);
/* some other db related code here */
I have shared the code. Could you please let us know what we need to change for SCA?
I just answered this question where OP did a great job on the question.
Perhaps her code can help you see how you need to implement this using JS in the
front-end and PHP in the backend.
Stripe - Payment Intents (3d secure issue)
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.
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
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