我的问题是:我必须在一个带有 conekta 的 iOS 应用程序中实现一些支付,我的服务器在 back4app 中运行得很好,之前我只有云中的 braintree 功能,现在我已经转移到连接器。 back4app 调用不断失败 iOS 给我错误 Invalid function 我从 braintree 的 sintax 中复制了它,我不擅长 Node.js 或 js。我用于云的代码:
// Requiring npm module
var braintree = require("braintree");
var conekta = require('conekta');
conekta.api_key = 'key_eYvWV7gSDkNYXsmr';
conekta.api_version = '2.0.0';
//conekta stuff
// Function for conekta
Parse.Cloud.define("conektaCustomer", function (request, response) {
var name = request.params.name;
var email = request.params.email;
var phone = request.params.phone;
var card = 'card';
var token_id = request.params.tokenId;
var lavado = request.params.total;
console.log(name + email + phone + card + token_id + lavado);
var customerID = conekta.Customer.create({
'name': name,
'email': guerrerovicente@gmail.com',
'phone': phone,
'payment_methods': [{
'type': card,
'token_id': token_id
}]
}, function(err, res) {
console.log(res.toObject());
});
order = conekta.Order.create({
"line_items": [{
"name": "Lavado",
"unit_price": lavado,
"quantity": 12
}],
"shipping_lines": [{
"amount": 0,
"carrier": "Automozo"
}],
"currency": "MXN",
"customer_info": {
"customer_id": customerID.id
},
"shipping_contact":{
"phone": customerID.phone,
"receiver": customerId.name,
"address": {
"street1": "Automozo",
"city": "Monterrey",
"state": "Nuevo Leon",
"country": "MX",
"postal_code": "64630",
"residential": true
}
},
"amount": lavado,
"charges":[{
"payment_method": {
"token_id": token_id,
"type": "card"
}
}]
}, function(err, res) {
console.log(res.toObject());
});
});
// Initializing gateway
var gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: "rw4ty7nn96t8kzcz",
publicKey: "qd77d84sy3836qbx",
privateKey: "8fc74c88de4a7b8acf417aadfb92f6c5"
});
// Function for client token generation
Parse.Cloud.define("generateToken", function(request, response) {
var clientId = request.params.clientId;
console.log(clientId)
gateway.clientToken.generate({
customerId: clientId
}, function (err, res) {
if (err) {
console.log(err);
response.error(err);
} else {
response.success(res.clientToken);
}
});
});
// Function for checkout
Parse.Cloud.define("checkout", function (request, response) {
var nonce = request.params.payment_method_nonce;
var amountPayed = request.params.amount;
var clientId = request.params.customerId;
console.log(clientId);
console.log(nonce);
console.log(amountPayed);
// Use payment method nonce here, for example:
gateway.transaction.sale({
amount: amountPayed, // $ 10.00 sale
paymentMethodNonce: nonce,
customerId: clientId,
options: {
submitForSettlement: true
}
}, function (err, result) {
if (err) {
response.error(err);
} else {
response.success();
}
});
});
//create empty customer id
Parse.Cloud.define("newCutomer", function (request, response) {
gateway.customer.create({}, function (err, result) {
if (err) {
console.log(err);
response.error(err);
} else {
console.log(result.customer.id);
response.success(result.customer.id);
}
});
});
//create new customer for cc save?
Parse.Cloud.define("createWithNonce", function (request, response) {
var clientNew = request.params.clientId;
var nonceFromTheClient = request.params.payment_method_nonce;
console.log("here");
console.log(nonceFromTheClient);
gateway.customer.create({
firstName: "Charity",
lastName: "Smith",
paymentMethodNonce: nonceFromTheClient
}, function (err, result) {
result.success;
// true
result.customer.id;
// e.g 160923
console.log(result.customer.id);
result.customer.paymentMethods[0].token;
// e.g f28wm
if (err) {
console.log(err);
response.error(err);
} else {
response.success(result.customer.id);
}
});
});
在 iOS 中:
func makeCardPayment() {
do {
try PFCloud.callFunction("conektaCustomer", withParameters: ["name":nameUser, "email": "guerrerovicente@gmail.com", "phone":numeroDeTelefono, "tokenID":"tok_test_visa_4242", "total":monto])
} catch let error {
print(error.localizedDescription)
}
}
它只是抛出无效函数,仅此而已,有什么帮助吗?
最佳答案
因此,我在此处和函数“conektaCustomer”中的第 21 行进行了检查,您需要添加引号,如下面的行:
var customerID = conekta.Customer.create({
'name': name,
'email': 'guerrerovicente@gmail.com',
'phone': phone,
'payment_methods': [{
'type': card,
'token_id': token_id
}]
}, function(err, res) {
console.log(res.toObject());
});
如果您继续遇到此无效函数问题,将需要进一步调查。
关于javascript - 云代码无效功能的back4app问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42322280/
如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby
在rails源中:https://github.com/rails/rails/blob/master/activesupport/lib/active_support/lazy_load_hooks.rb可以看到以下内容@load_hooks=Hash.new{|h,k|h[k]=[]}在IRB中,它只是初始化一个空哈希。和做有什么区别@load_hooks=Hash.new 最佳答案 查看rubydocumentationforHashnew→new_hashclicktotogglesourcenew(obj)→new_has
我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("
我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie
我的主要目标是能够完全理解我正在使用的库/gem。我尝试在Github上从头到尾阅读源代码,但这真的很难。我认为更有趣、更温和的踏脚石就是在使用时阅读每个库/gem方法的源代码。例如,我想知道RubyonRails中的redirect_to方法是如何工作的:如何查找redirect_to方法的源代码?我知道在pry中我可以执行类似show-methodmethod的操作,但我如何才能对Rails框架中的方法执行此操作?您对我如何更好地理解Gem及其API有什么建议吗?仅仅阅读源代码似乎真的很难,尤其是对于框架。谢谢! 最佳答案 Ru
我有两个Rails模型,即Invoice和Invoice_details。一个Invoice_details属于Invoice,一个Invoice有多个Invoice_details。我无法使用accepts_nested_attributes_forinInvoice通过Invoice模型保存Invoice_details。我收到以下错误:(0.2ms)BEGIN(0.2ms)ROLLBACKCompleted422UnprocessableEntityin25ms(ActiveRecord:4.0ms)ActiveRecord::RecordInvalid(Validationfa
我的假设是moduleAmoduleBendend和moduleA::Bend是一样的。我能够从thisblog找到解决方案,thisSOthread和andthisSOthread.为什么以及什么时候应该更喜欢紧凑语法A::B而不是另一个,因为它显然有一个缺点?我有一种直觉,它可能与性能有关,因为在更多命名空间中查找常量需要更多计算。但是我无法通过对普通类进行基准测试来验证这一点。 最佳答案 这两种写作方法经常被混淆。首先要说的是,据我所知,没有可衡量的性能差异。(在下面的书面示例中不断查找)最明显的区别,可能也是最著名的,是你的
几个月前,我读了一篇关于rubygem的博客文章,它可以通过阅读代码本身来确定编程语言。对于我的生活,我不记得博客或gem的名称。谷歌搜索“ruby编程语言猜测”及其变体也无济于事。有人碰巧知道相关gem的名称吗? 最佳答案 是这个吗:http://github.com/chrislo/sourceclassifier/tree/master 关于ruby-寻找通过阅读代码确定编程语言的rubygem?,我们在StackOverflow上找到一个类似的问题:
当我在我的Rails应用程序根目录中运行rakedoc:app时,API文档是使用/doc/README_FOR_APP作为主页生成的。我想向该文件添加.rdoc扩展名,以便它在GitHub上正确呈现。更好的是,我想将它移动到应用程序根目录(/README.rdoc)。有没有办法通过修改包含的rake/rdoctask任务在我的Rakefile中执行此操作?是否有某个地方可以查找可以修改的主页文件的名称?还是我必须编写一个新的Rake任务?额外的问题:Rails应用程序的两个单独文件/README和/doc/README_FOR_APP背后的逻辑是什么?为什么不只有一个?
只是想确保我理解了事情。据我目前收集到的信息,Cucumber只是一个“包装器”,或者是一种通过将事物分类为功能和步骤来组织测试的好方法,其中实际的单元测试处于步骤阶段。它允许您根据事物的工作方式组织您的测试。对吗? 最佳答案 有点。它是一种组织测试的方式,但不仅如此。它的行为就像最初的Rails集成测试一样,但更易于使用。这里最大的好处是您的session在整个Scenario中保持透明。关于Cucumber的另一件事是您(应该)从使用您的代码的浏览器或客户端的角度进行测试。如果您愿意,您可以使用步骤来构建对象和设置状态,但通常您