Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to use JMSPaymentCoreBundle with JMSPaymentPaypalBundle and I can't find a clear example anywhere on how to do it.
I've done all steps specified in the documentation and I'm not able to get it working. Can anybody help me please?
Payum bundle supports jms payments via the bridge. The links describes how to get started.
Usage of the bundle gives you several advantages:
Secured capture action.
Have credit card form, can ask user for credit card
Ability to easy setup IPN. Notify action is also secured.
Built-in support of all omnipay gateways (25 +), jms plugins (+ 10) and payum native libs.
Payum paypal lib supports recurring payment and digital goods out of the box.
Storages integrated into payment process so you do not have worry about data that might be lost.
Domain friendly. Indeed Payum provide some models but it does not restrict you to use them.
It already supports PSR-0 logger. In dev it logs executed payum actions, to easy debug (Visit symfony profile logs tab).
It is possible setup several payments (one paypal account for EU and one for US for example)
Extremely customizable. Add your custom payum actions, or extensions, or storages.
There is a symfony sandbox (code|web) to help you to start.
P.S. It is not the full list of features.
The default way to create a payment instruction is through the jms_choose_payment_method form:
$form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
'amount' => 12.99,
'currency' => 'EUR',
'default_method' => 'payment_paypal', // Optional
'predefined_data' => array(
'paypal_express_checkout' => array(
'return_url' => $this->get('router')->generate('payment_complete', array(
'number' => $order->getOrderNumber(),
), true),
'cancel_url' => $this->get('router')->generate('payment_cancel', array(
'number' => $order->getOrderNumber(),
), true)
),
),
));
You can also create a payment instruction manually:
use JMS\Payment\CoreBundle\Entity\ExtendedData;
use JMS\Payment\CoreBundle\Entity\Payment;
use JMS\Payment\CoreBundle\PluginController\Result;
use JMS\Payment\CoreBundle\Plugin\Exception\ActionRequiredException;
use JMS\Payment\CoreBundle\Plugin\Exception\Action\VisitUrl;
use JMS\Payment\CoreBundle\Entity\PaymentInstruction;
$extendedData = new ExtendedData();
$extendedData->set('return_url', $this->get('router')->generate('payment_complete', array(
'number' => $order->getOrderNumber(),
), true));
$extendedData->set('cancel_url', $this->get('router')->generate('payment_cancel', array(
'number' => $order->getOrderNumber(),
), true));
$instruction = new PaymentInstruction((float)$order->getCharge() > 0 ? $order->getCharge() : $order->getAmount(), 'EUR', 'paypal_express_checkout', $extendedData);
$this->get('payment.plugin_controller')->createPaymentInstruction($instruction);
$order->setPaymentInstruction($instruction);
$em = $this->get('doctrine.orm.entity_manager');
$em->persist($order);
$em->flush();
My payment_complete route looks like:
public function completeAction(Booking $order)
{
$instruction = $order->getPaymentInstruction();
if (($instruction->getAmount() - $instruction->getDepositedAmount()) > 0) {
if (null === $pendingTransaction = $instruction->getPendingTransaction()) {
$payment = $this->get('payment.plugin_controller')->createPayment($instruction->getId(), $instruction->getAmount() - $instruction->getDepositedAmount());
} else {
$payment = $pendingTransaction->getPayment();
}
$result = $this->get('payment.plugin_controller')->approveAndDeposit($payment->getId(), $payment->getTargetAmount());
if (Result::STATUS_PENDING === $result->getStatus()) {
$ex = $result->getPluginException();
if ($ex instanceof ActionRequiredException) {
$action = $ex->getAction();
if ($action instanceof VisitUrl) {
return new RedirectResponse($action->getUrl());
}
throw $ex;
}
} else if (Result::STATUS_SUCCESS !== $result->getStatus()) {
throw new \RuntimeException('Transaction was not successful: '.$result->getReasonCode());
}
}
$order->setTransactionAmount((float)$order->getAmount());
$creditPurchased = (float)$order->getCharge() > (float)$order->getAmount() ? (float)$order->getCharge() - (float)$order->getAmount() : 0;
$em->persist($order);
$em->flush();
I've got it running going through http://jmsyst.com/bundles/JMSPaymentCoreBundle/master/usage
Related
I am trying to work with the WooCommerce REST API. So far I have installed the official package and created an index.php file with this code in it:
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
use Automattic\WooCommerce\HttpClient\HttpClientException;
$woocommerce = new Client(
'http://me.commerce.loc/', // Your store URL
'ck_9dadcf73d58fec8b0860bced4b0997d7b3b0f93e', // Your consumer key
'cs_e63d694c035444c45355339171c682052b2707eb', // Your consumer secret
[
'wp_api' => true, // Enable the WP REST API integration
'version' => 'wc/v3' // WooCommerce WP REST API version
]
);
print "<pre>";
print_r($woocommerce);
die();
Printing out $woocommerce gives me this object:
Automattic\WooCommerce\Client Object
(
[http] => Automattic\WooCommerce\HttpClient\HttpClient Object
(
[ch:protected] =>
[url:protected] => http://me.commerce.loc/wp-json/wc/v3/
[consumerKey:protected] => ck_9dadcf73d58fec8b0860bced4b0997d7b3b0f93e
[consumerSecret:protected] => cs_e63d694c035444c45355339171c682052b2707eb
[options:protected] => Automattic\WooCommerce\HttpClient\Options Object
(
[options:Automattic\WooCommerce\HttpClient\Options:private] => Array
(
[wp_api] => 1
[version] => wc/v3
)
)
[request:Automattic\WooCommerce\HttpClient\HttpClient:private] =>
[response:Automattic\WooCommerce\HttpClient\HttpClient:private] =>
[responseHeaders:Automattic\WooCommerce\HttpClient\HttpClient:private] =>
)
)
Is it possible to get wooCommerce data through this object? If no then how can I do it?
Thank you very much.
You do not require to add above code or create index.php
just use this end point to get all orders list : https://example.com/wp-json/wc/v3/orders
To get all Products : https://example.com/wp-json/wc/v3/products
This way you can get list of order and products.
To use rest api and do all operations in woocommerce using rest api please refer this link : https://woocommerce.github.io/woocommerce-rest-api-docs/
There are two woocommerce rest api versions which are V2 and V3 you can use any from this.
the API works when ck_ and cs_ keys are for Admin and returns the std class object but when keys are for a different user returns You do not have permission to read this product 401(woocommerce_api_user_cannot_read_product) Error response: even when user has read/write privileges. but goes ahead to create the product in the database. Any help on this issue is highly appreciated
require_once( 'lib/woocommerce-api.php' );
$options = array(
'debug' => true,
'return_as_array' => false,
'validate_url' => false,
'timeout' => 30,
'ssl_verify' => false,
);
try {
$client = new WC_API_Client( $the_url, 'ck_xxxx', 'cs_xxxx', $options);
Try adding into your $options array:
$options['query_string_auth'] = true;
As noted in the documentation this will "Force Basic Authentication as query string true" in other words it will append your consumer key and consumer secret to your request URL as a query string. This is only supported on HTTPS.
I am creating my own payment bundle with Payum. I managed to correctly generate the payment order with my payment entity and my bundle redirects correctly to the payment page of my entity (where the user enters their card and PIN number). The problem is that I can not validate the payment. My payment entity only allows me to configure a single payment confirmation asynchronous call url (and it does not allow me to send a parameter with the notification url in each order).
How do I have to proceed to obtain the payment token? Is there any way to get the payment token from the order id and then validate it?
Ok, i think i've made it. This is the "solution":
First of all, i had to create an url for notifications with a controller atached.
payum_ceca_notification_url:
path: /payum/ceca/bank-notification
methods: [GET, POST]
defaults:
_controller: CecaPlugin:Notify:do
Then in my doAction:
public function doAction(Request $request):Response
{
$params = $request->request->all();
$order_id = (int) $params['Num_operacion'];
$payment = $this->container->get('sylius.repository.payment')->findOneBy(['id' => $order_id]);
$details = $payment->getDetails();
$cecaOptions = array(
'Environment' => $details['Environment'],
'MerchantID' => $details['MerchantID'],
'AcquirerBIN' => $details['AcquirerBIN'],
'TerminalID' => $details['TerminalID'],
'ClaveCifrado' => $details['ClaveCifrado']);
$apiCeca = new ApiCeca($cecaOptions);
$apiCeca->setFormHiddens(array(
'Num_operacion' => $details['Num_operacion'],
'Importe' => $details['Amount'],
'URL_OK' => $details['url_ok'],
'URL_NOK' => $details['url_nok'].'?pagocancelado=1'
));
// check my sign vs the sign sent to me by payment entity
$apiCeca->checkTransaction($params);
$payment->setState(PaymentInterface::STATE_COMPLETED);
$payment->getOrder()->setPaymentState(OrderPaymentStates::STATE_PAID);
$manager = $this->container->get('sylius.manager.payment');
$manager->persist($payment);
$manager->flush();
return new Response();
}
I know that it is not the most elegant solution but it is a solution that works, marks the order as paid.
I'm using Laravel's Cashier for billing which is great. I'm trying to be good and keep my code tested but I'm having trouble "faking" a user with a subscription.
I've tried:
$user = App\Models\User::create([
'first_name' => $this->faker->firstName,
'last_name' => $this->faker->lastName,
'email' => $this->faker->email,
'password' => 'password1234',
'stripe_plan' => 'name_of_plan',
'stripe_active' => 1
]);
$this->be($user);
But if I then check $user->onPlan('name_of_plan') I get false :(
Is there a way to do this? As I'm sure you can appreciate I don't really want to launch the payment system until I've got tests to back it up!
Check that 'stripe_plan' and 'stripe_active' are defined as fillable for User. If they aren't then it may not be actually setting those values in User::create() which is why your test fails.
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, BillableContract {
use Authenticatable, CanResetPassword, Billable;
protected $table = 'users';
protected $fillable = [
'first_name',
'last_name',
'email',
'password',
'stripe_plan',
'stripe_active'
];
}
I'm working with SiteCore and I need to pull some data out of the software via either that API or the SQL database using a PHP script. The reason I say both are possible is because even if the database changes later on, that doesn't matter to me.
Anyway...
I'm trying to pull any data fields that I can get from a particular issue. This is my SOAP code so far, and it connects to the service and such, but the return isn't what I need...
try
{
$client = new SoapClient('http://localhost:8083/sitecore/shell/webservice/service.asmx?WSDL');
$credentials = array('Password' => 'mypassword','Username' => 'sitecore\myusername');
$Current_Issue = array(
'id' => '{043B69BA-3175-4184-812F-C925CE80324E}',
//'language' => 'en',
//'version' => '1',
//'allFields' => 'true',
'databaseName' => 'web',
'credentials' => $credentials
);
$response = $client->GetItemMasters($Current_Issue);
print_r($response);
}
catch(SoapFault $e)
{
echo $e->getMessage();
}
catch(Exception $e)
{
echo $e->getMessage();
}
This is my output:
stdClass Object
(
[GetItemMastersResult] => stdClass Object
(
[any] => <sitecore xmlns=""/>
)
)
ANY help is appreciated. If anybody knows an example SQL query that I can use, that would be just as useful as an alternative method.
Thanks
If you are running Sitecore 6.5 / 6.6 you may want to take a look at the Sitecore Item Web API which was released yesterday (5/11/12).
http://sdn.sitecore.net/Products/Sitecore%20Item%20Web%20API.aspx
This allows you to perform RESTful operations against Sitecore items without the need for the old web service / SOAP interface. Using this module you can receive a JSON representation of a Sitecore item or collection of items and even post back changes. You may find it easier to work with :)
If you have to use the SOAP interface, are you sure that your items are published ? Try changing the databaseName -> 'master' and see if you get any results. Other things to check are the permissions of the user credentials you are using.